Attach-focus not working in aurelia-dialog
Asked Answered
D

1

8

I have the following:

<ai-dialog>
    <ai-dialog-header style="display:flex;justify-content:space-between">
        <span>New Person</span>
        <i class="fa fa-close" style="cursor:pointer" click.delegate="controller.cancel()"></i>
    </ai-dialog-header>

    <ai-dialog-body>
        <div style="display:flex;flex-grow: 1">
            <div class="field">
                <div class="field-title">First Name</div>
                <div class="field-value">
                   <input style="flex-grow:1" type="text" attach-focus="true" value.bind="criteria.firstName & validate" />
                </div>
            </div>
            ....
        </div>
     </ai-dialog-body>

     <ai-dialog-footer>
         ...
     </ai-dialog-footer>

When the dialog is displayed, I'm expecting first name input box to have focus but nothing has focus -- I manually have to click in the box to set focus.

Any thoughts?

Danaus answered 19/1, 2017 at 16:40 Comment(4)
One tiny possibility is that attach-focus doesn't work if you have developer console open and active, since the focus jumps to the console log input.Teador
Thanks, tried closing the console and still no magic.Danaus
Hmm, unable to reproduce. gist.run/?id=e92d59f39898802e6fdaa6f1644845a5Edik
Always worth asking, do you have the latest repositories? Do you have any other custom attributes messing things up? Can you create a new skeleton project and reproduce the issue there? Could the flex style be causing some weird focus issues (it's a slim possibility)? Could the validate binding on your value be causing issues?Monto
H
0

Try the following: focus.bind="true"

<input style="flex-grow:1" type="text" focus.bind="true"...

You could also make the focus depending on the model what you didn't need here.

Here are more details: http://aurelia.io/blog/2015/06/05/building-aurelias-focus-attribute/

Hawfinch answered 9/7, 2020 at 12:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.