[whatwg] Two propositions for the autofocus attribute

Kit Grose kit at iqmultimedia.com.au
Thu Apr 15 17:44:37 PDT 2010


On 16/04/2010, at 9:08 AM, Jonas Sicking wrote:

> While we could deploy a bunch of heuristics, it seems much simpler to
> just say that it is the *first* element with autofocus that should
> receive focus. I can't think of any significant downsides with this.

I agree with you both generally, but I disagree that there are no downsides. I imagine the main use-case where this sort of behaviour might be expected is a Javascript application which dynamically adds a new form to the page based on some user interaction and one of those fields should be autofocused when it's been added to the DOM.

For instance, picture the Gmail model. When you first load, the autofocus attribute could conceivably be on the inbox search field. When you click Compose, the compose form will be dynamically added and the "To" field should be autofocused (but the search field is still on-screen)

I suppose you could argue that it'd be up to the application to go and *remove* the previous autofocus attribute from the search field, or should manage focus as they currently do with HTMLInputElement.focus(), but I can see the simplicity that automatically moving the focus would represent for these sorts of applications.

—Kit


More information about the whatwg mailing list