[whatwg] Two propositions for the autofocus attribute
Ian Hickson
ian at hixie.ch
Tue Aug 24 17:02:00 PDT 2010
On Thu, 29 Jul 2010, Paul Ellis wrote:
> >
> > In this kind of situation, you'd just use focus(). There's not much
> > point using autofocus if you're already running code; the main win of
> > the attribute is simplifying the page and not requiring scripting, but
> > if you've already got code the cost of an additional focus() is
> > minimal.
>
> I agree that if you are comparing:
>
> var html = "<input id='mySearch' type='text' autofocus>";
> document.getElementById('myDiv').innerHTML = html;
>
> to
>
> var html = "<input id='mySearch' type='text'>";
> document.getElementById('myDiv').innerHTML = html;
> document.getElementById('mySearch').focus();
>
> then the cost is minimal.
>
> However there are a lot of instances of scripts retrieving HTML blobs
> where it is much more convenient and compatible with the work flow that
> the focus is determined using HTML instead of JS. If you take a common
> example such as a Facebook-style modal "dialog" you can see that it
> would be easy to return HTML with an <input autofocus>. Any HTML
> editor/generator could set focus this way and it would be easy to convey
> that functionality to the UA as it is part of the content.
Sure but in this kind of scenario the focus is already somewhere, so the
user agent wouldn't move the focus automatically anyway -- it would assume
that would annoy the user.
I think long-term we're better off adding an explicit <dialog> element
where we can do this kind of thing (and then it would make sense to reuse
autofocus).
> It would seem to me that focus should always be set on the last element to
> have autofocus.
That's what we used to have, but it makes the focus jump around while the
page is loading, which is why we changed this in the first place.
--
Ian Hickson U+1047E )\._.,--....,'``. fL
http://ln.hixie.ch/ U+263A /, _.. \ _\ ;`._ ,.
Things that are impossible just take longer. `._.-(,_..'--(,_..'`-.;.'
More information about the whatwg
mailing list