W3C home > Mailing lists > Public > whatwg@whatwg.org > April 2010

[whatwg] Two propositions for the autofocus attribute

From: Benjamin Hawkes-Lewis <bhawkeslewis@googlemail.com>
Date: Sun, 25 Apr 2010 21:19:40 +0100
Message-ID: <j2ode4cf6d81004251319m50b2d9d3iae67bb580b2bb01c@mail.gmail.com>
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
Received on Sunday, 25 April 2010 13:19:40 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:22 UTC