[whatwg] Two propositions for the autofocus attribute

Benjamin Hawkes-Lewis bhawkeslewis at googlemail.com
Sun Apr 25 13:19:40 PDT 2010

On Thu, Apr 15, 2010 at 11:43 PM, Mounir Lamouri
<mounir.lamouri at gmail.com> wrote:
> To better fulfill this need, I think we should add two rules for
> the autofocus attribute behavior: - only the first element with
> the autofocus attribute specified should get the focus. All other
> autofocus requests should be ignored. This is exactly the same for
> authors because they should not have more than one element with
> the autofocus attribute specified but that would be better for the
> user because it will prevent autofocus to move from a field to
> another.

But it wouldn't prevent /focus/ moving, since publishers could call
focus(), so from a user perspective I can't see the advantage?

> - if an element with the autofocus attribute specified is inserted
> after the load event (or the 'DOMContentLoaded' event) it should
> not get the focus. Having an element inserted in the document with
> the autofocus attribute specified is just a way to prevent using
> .focus(). That is not why autofocus has been introduced. If an
> author want to focus an element after the load event, he/she
> should use .focus().

I think focusing using autofocus is better than forcing developers
to use focus().

Consider a dialog box added to a webpage using JS. "autofocus"
allows separation of concerns between the layout of controls within
the dialog and the script. If you use focus() only, you must update
the script with knowledge of which control to focus as the layout of
controls changes. If you use "autofocus", the first focused control
in the dialog can be changed without touching the script.

Maybe I'm just missing the problem you're trying to solve here?

Benjamin Hawkes-Lewis

More information about the whatwg mailing list