For the last couple of months (yes, sorry…) I’ve investigated the domain of “sequential navigation” (what you do, when you hit Tab). What follows are a couple of ideas regarding the Element-level focus APIs from an author’s (“web developer”) perspective.
- There is no simple way to find out if an element is focusable or tabbable (i.e. accessible through sequential navigation). Since user agents already maintain internal focusable flags per element and the sequential navigation list, exposing the readonly boolean properties
focusable
andtabbable
looks like a small feat. - Additionally to (1) the flags could be made accessible via CSS pseudo-classes
:focusable
and:tabbable
. - Alternatively or additionally to (1) the ElementCollections of focusable and tabbable child elements should be made available per element. This is useful to do things like (4) manually. user agents vary on what is focusable/tabbable and figuring this out accurately is cumbersome.
- WAI ARIA Authoring Practices for Modal Dialogs says “Tab Focus must be held within the dialog until it is cancelled or submitted”. This is true for Chrome’s implementation of the
<dialog>
element. While it is possible for JavaScript to keep focus within a given element, that interception will always prevent the user from reaching the user agent’s UI (like address bar) via Tab. For author’s the best solution would be to add the “trap-focus” attribute to the element in which focus must be held (container). That way the user agent can limit the sequential navigation list to the tabbable elements of the container element and allow normal passing of focus to user agent UI upon Tab. As a bonus authors don’t have to employ loads of JavaScript to achieve the same thing. - The document-wide nature of positive tabindex attributes (e.g. [tabindex=“3”]) make localized re-ordering of the navigation sequence painfully hard. The ShadowDOM can be used to localize the effects of positive
tabindex
attributes, and the CSS propertyorder
is being petitioned to affect navigation order. Both approaches come with restrictions and side-effects. It might help thinking of the author’s need more along the lines of how the radio button works. Specifically the grouping mechanism. Along this line of thinking, the element<input … tabindex="3" tabgroup="gustav">
would still be taken out of the dom-orderd document’s navigation sequence, but not sorted to the beginning of the navigation sequence like now. Instead, the new (inert) element<tabgroup name="gustav">
would be replaced with the captured taborder sequence, in dom order of its occurrence.
I consider 1-3 easy requests and 4 a simple enough request. 5 is an idea I’ve been toying with and wanted to get some feedback on.