Hacker News new | ask | show | jobs
by playpause 1498 days ago
I agree, autofocusing a search field that's in the header of every page is not generally appropriate, but that's not specifically about accessibility. It would be annoying for anyone on a mobile device (keyboard pops up on every page), and the focus ring and/or blinking cursor would be distracting.

What about cases where it is appropriate to autofocus the search input (as it's the primary action on the page) but where there also might (sometimes) be an important text notice above the search input? Sighted users would see the notice fine, while screenreader users would be 'teleported' (MDN's word) straight past it, missing the notice.

2 comments

I believe it's up to screen reader developers to come up with innovative ways of making the web as it currently exists more usable, rather than requiring the millions of websites out there to accommodate the technology's current limitations. In this case, perhaps screen readers need to somehow intelligently read nearby text when a control immediately receives focus on page load.
No. Browsers already parse the page to produce an accessibility tree that's provided through the operating system's accessibility API. Screen readers attempting to supplement what's provided through that API by re-parsing the page should be a last resort and is bound to be error-prone.

Designers and developers need to learn that what they make will be, and should be, experienced in ways different than how they do. Content is experienced linearly, not always in two dimensions, and semantics can make programmatically explicit what is only implied visually (like heading text being bigger and bolder).

The prevalence of smartphones and responsive design have helped somewhat to expand people's understanding of how using digital experiences can vary. There's a lot more that can be learned.

Aside from not using autofocus on the input field at all, another existing option is to programmatically associate the preceding block of text by giving the block a unique id and referencing it from the input using an aria-describedby attribute; after a screen reader reads the input's accessible name, it will read the associated description.

> while screenreader users would be 'teleported' (MDN's word) straight past it, missing the notice.

Autofocus in that case seems like reasonable and expected behavior. Isn't it up to the tools (e.g. screen reader, etc) to accommodate the expected behavior, rather than for the reasonable and expected behavior to change?

No. It is reasonable and expected that some users experience page content linearly so designers and developers have to create experiences that takes that into account. That includes not skipping important content. If it's important, don't skip it. If it's not important, maybe it's okay to skip it but there should be means for users to explore and discover what's on the page (like give the preceding block of text a heading that indicates what that section of content is about).
Hmm. "All users should experience the page linearly because some do" is not really an argument that works.
A sighted user with a cursor or touchscreen can be as non-linear as the size of the viewport and the layout allows.

All designers should design the linear experience as well as the non-linear experience because the linear is all some users will have. Responsive design is a move in that direction, a smartphone portrait display is much narrower than a laptop display so the content tends to be in a more linear layout. Experiences through voice assistants are also linear.

Let's just step back and state our terms. Are we agreeing that website placing the cursor in a search box is an example of autofocus?

I believe it is reasonable to do this if there is no other purpose for the page.

If I understand correctly, it is your contention this is unreasonable because it will skip all of the other information about the page for screen readers.

My question is why screen readers cannot, or should not, handle this special case? Isn't there an argument that it helps users with hand-eye coordination problems? I am absolutely for a11y, but when there is a trade-off in degraded experience for the majority, I'd like to hear arguments why the interpretive tools used by the minority cannot handle that interpretation.