-
Notifications
You must be signed in to change notification settings - Fork 378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mechanism for setting the tabindex focus flag without sprouting tabindex attribute? #762
Comments
Strong +1. Do you think it's worth exposing both of tabindex's capabilities here, or just one? They are:
I think there are common built-in elements whose behavior falls into each of these categories, although it may be OS dependent. |
+1 and I would like to see both 😀 |
In all honesty, I've never understood why But that aside, I guess allowing focusable things to also opt out of the tab order is probably useful for managing focus within complex components. |
@alice |
@annevk True, although I've seen that cause more undesirable behaviour than desirable. |
Whatever mechanism we use for |
Wouldn't it be great if an element became focusable just by setting its role to something that is known to be an interactive element as per the ARIA spec. Just like a button is implicitly focusable, if I set the role of an element to be a button, I would love for the browser to just take care of it for me. |
I seem to recall ARIA affecting behaviour in that way was a deal breaker in the past - ARIA's contract is that it only affects accessibility tree computation. (Edited to add:) |
Discussion at TPAC: We should keep in mind the concern that platform conventions differ, so we don't want to be in a position where authors can't match behaviour of the platform they are on. Consider a mode where you match some other element's behaviour... |
A possible API is:
If the |
@tkent-google I think that is the simplest design that could work. (Although I would change the name to be something less spec-focused and more intelligible to authors, but that doesn't matter for now.) However, the above discussion revealed a few other possibilities:
What do you think of these considerations? Maybe they are overcomplicating things, and we should just go with the simple boolean version. |
We have two categories of focusable elements in Chrome:
If we support only these two categories, we should add a boolean flag like |
Probably, see whatwg/html#938 (comment) onward for some discussion on this. It'd be good to first sort this out for existing features though, before exposing it to the world. |
Well, there's a third category, right? Elements like div, which are not focusable (without explicitly setting tabindex). So I think a tri-state is necessary if we want to support the range of capabilities. And, of those three categories, which does The big question is whether those three (?) categories of Chrome's are matched by other browsers. I am hopeful they kind of are, and the thread @annevk links to has some details I should re-read. We should try to confirm. It would be great if we could figure out the total set of behaviors that browsers want to expose. Then we could codify that model in the spec, better than the current text, and expose it to custom elements. I don't think that'll be too hard... |
@domenic, yes, there are three categories if we include non-focusable. I meant categories in default focusable elements. In Safari, the second category in my comment is not mouse-focusable even if Full Keyboard Access setting is "All controls".
|
Interesting! Maybe it's a bit early to start guessing at APIs, but this could point toward a setting like
Yep! I am just hoping that div-with-tabindex falls into those two categories, not some new category. |
I think the challenge here is designing this API to be future proof. We don't want to hard code what's exactly needed for existing platforms because that'd limit future platform that we can't even imagine exist today. |
Yeah, agreed. I think we can do that by using an enum instead of a boolean (and it looks like there will be 3+ options anyway). We can then expand that as needed. Would you be able to confirm the categories of behaviors currently present in Safari? |
Safari's behavior is that by default only form controls are tab focusable. Option + tab would focus every element that's focusable by default like link elements. Separately, every non-editable form element like buttons or input[type=submit] is not mouse focusable. In order to correctly describe WebKit's behavior, we'd need to be able to differentiate four states:
Note that the user can override the behavior of tab key to be more like option+tab in Safari's preferences.
I think enum value is problematic because that would mean that whenever a new platform shows up, or the platform convention changes, websites may need to adopt the change. Also, I don't think hard-coding the list of things Safari do today to the web platform is a good idea either. Specifying relative to builtin elements is an interesting idea although it's hard to differentiate editable input from non-editable input but perhaps input is an odd case due to its behavior completely changing based on |
TPAC 2019 discussion: https://www.w3.org/2019/09/17-components-minutes.html#item07 It mentioned possibility of borrowing concepts from ARIA. Does it mean using ARIA roles as high-level concepts? |
Apologies for the long comment. Hopefully it's at least clear. I think there are three fundamental states for focusability: an element is
I think the logic behind Safari's choices around how a user may focus certain elements is something along the lines of:
I think that comes down to three classes for built-in "user focusable" elements:
If we ruled out wanting to emulate non-editable form control behaviour
So that comes down to four categories:
That seems both simpler and more robust than using ARIA roles, in particular since we don't yet have parity between ARIA roles and HTML elements (there's no
|
The disconnect is that when I referred to tabs I meant window-level tabs, like this: For tabs like that, each is always in the tab focus order. What Alice screenshotted is a "segmented control" but may also reasonable be called tabs. I can confirm that it has the behavior she describes; it's a single stop in the tab order, it draws a focus ring around exactly one item, and it moves through the items with arrow keys. A similar thing is true of radio button groups in native UI; only the currently active radio button is in the tab order. Or, looked at another way, a radio button isn't a control, a radio button group is. Indeed, the segmented control is sort of an alternate presentation of a radio button group. WebKit even replicates this behavior of radio button groups in HTML when "Use keyboard navigation to move focus between controls" is enabled. I'm not sure this pattern is best represented. Under full keyboard access, radio buttons are individual elements that are always click-focusable, but, at least on macOS (not sure how this works on Windows), only the active one is in the tab cycle. It's reasonable for other elements intended to be part of a group to have this behavior. Less clear (to me) whether there is a need to not be click focusable in such a scenario. |
I'm pretty certain that behavior only exists if "Use keyboard navigation to move focus between controls" in (somewhat misleadingly labeled) Shortcut section of Keyboard in System Preferences is checked (I've confirmed this on 10.15.3 19D76). By default, you can't press tab key to focus any section title in Keyboard or any of the checkboxes. |
@othermaciej wrote:
@alice replied
If I understand the distinctions you're each making, you two are agreement on the relevant parts. Maciej mentioned that managed focus AppKit controls don't focus the sub-views, per se. But AppKit does style the sub-views and vends enough information for AT to understand the relationship... Somewhat similar to the concept of Alice mentioned that more web controls use the other managed focus technique: roving/roaming tabindex. (There's a demo video of r–ing tabindex in Example 2 of this 2014 WebKit post). Each technique is useful. In both cases, on Web or native platforms, the user experiences the same end result: one tab stop, with other non-Tab keypresses modifying the widget's sub-level focus or visible focus indicator. The distinction of whether the container or the sub-view gets actual focus feels like a implementation detail of the platform. |
Aside: should elements with |
Attributes that affect focusability (or should):
Feel free to edit this comment to add any I overlooked. |
I'm not sure what the latest is in this thread and proposal, but I'll drop a note that the eventual proposal should be sure to make the resulting controls interactive content. As whatwg/html#5414 points out this has an effect on |
Perhaps autofocus should also be considered within this issue, to take into account the case when FACE is upgraded? |
I think they might be orthogonal, but someone else may be able to correct me - i.e. |
Right, but it means that when the new way to make an element focused, is provided according to this discussion, it will not work with autofocus (or even worth, it will provide intermittent results). It seems reasonable to update autofocus spec so that the algorithm is also triggered when custom element is upgraded. |
I see - on document load, the element may not yet be focusable, since it hasn't yet upgraded. |
I've also stumbled upon on "always tab-focusable audio controls in Chrome regardless of tabindex". Had to do a JS workaround :( For some fast tab-navigation scenarios 6 audio controls being tabbed-through destroys the tab navigation usecase, especially when audio isn't supposed to be played often and tab navigation is supposed to be used often (in some crowd-sourcing scenarios) |
So, custom elements set as
|
"Safari would need to" may not be true. I see at least two options:
|
@alice wrote:
Above you mentioned roaming/roving tabindex as the primary justification for programmatic focus, but most of the examples I've seen toggle the state of those sub-controls between If so, maybe it's okay to force the author to make a custom element |
In chrome://settings/appearance, there is a setting that is similar to the Mac Safari setting, called: "Pressing Tab on a webpage highlights links, as well as form fields." @alice, would your proposal to have Safari adjust tab-focus by role also apply to Chrome in this context? |
Making custom elements always programmatically focusable doesn't seem like a backwards compatible change to me. During our work to make Safari to iPad load desktop sites, we encountered numerous websites including Microsoft Office 365 that move focus inadvertently(?) to multiple elements before the correct element is focused. Making previously non-programatically focusable element always programmatically focusable has a risk that it would make previously no-op |
Here's my attempt of summarizing the discussions we've had so far. In 2018 TPAC, we concluded that we wanted to respect platform differences. One approach considered is adding the ability to match other element's behavior. One of the simplest approach propsoed by tkent-google is to add a signle boolean like In 2019 TPAC, we discussed the idea of using ARIA role as a way of detecting which element is focusable. Alice proposed that if we ignored non-editable form control behavior, we can narrow the cateogires down to four: unfocusable, programatically focusable, user focusable but keyboard focusable depending on UA, and always keyboard focusable. Maciej then pointed out that Safari doesn't include all form controls in the tab order; only editable ones like After more bikeshedding, Alice suggested that we can have four categories: unfocusable, programmatically focusable, user focusable but UA dependent for tab order, and user focusable and always in tab order. Maciej points out that if we split "accepts text input" (i.e. editability) into its own property, then we need two states but suggested that tri-state is simpler: More recently, Domenic pointed out that this propopsal needs to also make the focusable custom element interactive content as it affects |
Wow, TIL. Yes, I agree Chrome should be consistent with whatever Safari decides (i.e. treating Custom Elements the same for focus as either |
This is definitely worth experimenting with; it would avoid the issues @rniwa mentioned. I had a play with doing this with I do seem to recall that there were some potential issues with this, but so far I can't remember what they may have been. I asked a colleague who works in front-end development, and they noted that not having a programmatic focus state means there is extra (and thus potentially error-prone) work when you want to move focus to something but not have it remain user-focusable after focus moves away. Maybe the solution there is an option to |
@alice wrote:
How would that be different than making all custom elements always programmatically focusable? Wouldn't it result in the same problems @rniwa mentioned on the Microsoft Office 365 web app? |
I meant to suggest that you would have to opt-in to overriding the focusability bit, e.g. If you're depending on While we're exploring options, we should keep our use cases in mind as well. I can really only think of two use cases for
Are there any other use cases I've missed? |
We discussed this at this week's web component meeting. @rniwa put forth an update to Apple's tri-state proposal referenced in his summary above. In this,
The difference between #2 and #3 would let Safari provide its distinct UI behavior in which focus skips components in category #3 by default. Various people expressed questions about how developers would distinguish between categories #2 and #3, particularly for new types of components that have no analogues among the existing HTML elements. E.g., one class of interesting components are list boxes and other elements that support typeahead (type some characters to select an item that begins with those characters). Do those components edit text? Given that Apple is the entity making the distinction, the suggestion was that Apple provide guidelines about how it would categorize various categories of elements whose focusability might conceivably be in question. Those guidelines could then be incorporated into the documentation of the One concern raised with this proposal is that, by default, WebKit does not focus components in category #2 — e.g., form controls like radio buttons — when the user clicks on them. That behavior might confuse or cause problems for a web developer using that #2 |
FWIW I continue to be excited about tri-state proposals that let custom elements continue to capture the same capabilities as built-in elements. And I am glad that this is orthogonal to other pieces of state (e.g., role). I am willing to help with updating @tkent-google's tri-state pull request (whatwg/html#5120) with appropriate new names and documentation, once folks have figured them out. |
I'd like to continue the discussion about programmatic focus, just to make sure we aren't missing any critical functionality by excluding it. I'd be interested to hear from @JanMiksovsky or any other web component developers whether the use cases I listed in #762 (comment) are the full range of what For (1) above, perhaps a worked example might help with intuition. Say you're developing a date picker widget. When the date grid dialog is open, you'd want to be able to programmatically move focus/selection among the days of the month shown, but only have the pre-selected month appear in the focus order. In this screenshot, the user had previously used the arrow keys to move focus/pre-selection to "1", and then used the tab key to move focus to the "previous month" button. If the user uses the tab key to move the focus back to the calendar grid, the "1" cell will be focused again. If the user clicks on any of the other days, or uses the arrow keys to select an adjacent day, that day will be focused and pre-selected (the selection not being committed until the user activates the 'Ok' button). I am interested in whether developers would tend to:
|
The problem I'm having is wrapping a native element (eg: <x-toolbar role=toolbar>
<x-button role=none tabindex=0>
#shadow
<button tabindex=0>Button 1</button>
</x-button>
<x-button role=none tabindex=-1>
#shadow
<button tabindex=-1>Button 2</button>
</x-button>
</x-toolbar> This works fine and Chrome and will show the AOM tree correctly. I created another setup, but it requires now rewrite my mostly universal roving tabindex code for a custom attribute ( <x-listbox role=toolbar>
<x-listbox-option role=none x-tabindex=0>
#shadow
<input type=checkbox role=option tabindex=0 name=option1>
</x-listbox-option>
<x-listbox-option role=none x-tabindex=-1>
#shadow
<input type=checkbox role=option tabindex=-1 name=option2>
</x-listbox-option>
</x-listbox> Who's in the right here? Chrome or Firefox? Firefox doesn't seem to like a focusable element with |
Certain HTML elements are focusable without having an explicit
tabindex
attribute:a
elements that have anhref
attributelink
elements that have anhref
attributebutton
elementsinput
elements whose type attribute are not in the Hidden stateselect
elementstextarea
elementssummary
elements that are the first summary element child of a details elementIt would be nice if custom elements could also opt in to being focusable without having to sprout a
tabindex
attribute - such that if page authors removed thetabindex
attribute, the element was still focusable.It seems like this would be something that might fit in with whatever new API comes out of #758.
The text was updated successfully, but these errors were encountered: