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

[whatwg] Two propositions for the autofocus attribute

From: Mounir Lamouri <mounir.lamouri@gmail.com>
Date: Fri, 16 Apr 2010 00:43:00 +0200
Message-ID: <4BC79674.2070000@gmail.com>

At the moment, the autofocus attribute specification [1] is quite
permissive: only one element should have the autofocus enabled in the
document but each time an element with autofocus is inserted into the
document, the UA should give it the focus. The UA can disable the
autofocus request for some reasons like if the user is already typing
into a document.

As far as I know, the autofocus attribute has been introduced to
autofocus a form field during the load process to prevent doing that in
js and thus focusing an element after the load of the document.

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
- 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().

What is your opinion about these two propositions ?

[1] http://dev.w3.org/html5/spec/forms.html#attr-fe-autofocus

Received on Thursday, 15 April 2010 15:43:00 UTC

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