cody-dot-js / codyaprice.com-legacy

Personal website
https://codyaprice.com
MIT License
1 stars 0 forks source link

[blog post] `.focus`ing on a11y when used with client side VDOM routing #141

Open cody-dot-js opened 4 years ago

cody-dot-js commented 4 years ago

The AT virtual indicator, why do?

I'll tell you, I don't know

Contrary to your intuition or common sense, the virtual indicator does not follow 1-to-1 with DOM focus. Stupid, I know. When can you see this? Well, it's most apparent when using VDOM and client-side routing, e.g. React and React Router DOM.

Since client-side routing & VDOM doesn't do a hard refresh, the content of the page may visually change, but the AT never fully resets. So if you expect the focus to reset to the beginning of your content, well... sorry, but that ain't how it works (unfortunately). It varies from AT to AT (screw you voiceover 😡), but generally, if the entire page tree changes, the focus will return to the document.body (if you check the document.activeElement). Right, so that's where the focus is, but where's the virtual indicator?? It depends and is not quite deterministic. Sometimes it will jump around the page until it sticks somewhere and sometimes it will try to focus on the element beneath its last position.