Closed dandclark closed 2 years ago
I personally like the idea of considering that while a selectmenu is active focus is within it and tab moves you between focusable items in the selectmenu - which might help us with #540.
If we consider the enter set of options in a <selectmenu>
to be a single tab item we could automatically focus the first focusable item when you open the selectmenu (usually the group of options) and this would mean that pressing tab will move focus to the next tabbable item (usually outside the selectmenu, closing it implicitly with the current option selected). However, in the presence of other interactive content inside the selectmenu you could tab between that content.
@flackr that doesn't sound like a <selectmenu>
.
Perhaps we need a more complex component which could be called <selectdialog>
which could do the kind of thing you are requesting. It could be used for calendar widgets, colour pickers etc. which don't neatly fit into a <selectmenu>
I agree, I don't think we've really appreciated the full complexity of will need to be nailed down in order to allow freeform mixed interactive content in a <selectmenu>
.
Just in the context of tabbing, @flackr your suggestion is interesting, but runs into problems with trying to figure out how selection should work in a single-tab-stop vs. multi-tab-stop scenario. Generally, someone would expect tabbing away to select -- so what happens to their selection if they try to tab away, and find there's a random button in the select menu, and then tab again to get out of it? In that case, they'd clearly expect the selection to be preserved, but I can also clearly imagine other scenarios with more non-option content where that would not be the case.
Then there's the case of something like this:
<selectmenu>
<option>apple</option>
<option>banana</option>
<input type="text">
<option>kiwi</option>
</selectmenu>
It would need to be turned into a set of children with two separate listboxes inserted by the browser, and I'm really not sure how selection, not to mention surfacing of the # items and arrowing, would work in that scenario:
<div role="dialog">
<div role="listbox">
<option>apple</option> // let's say the user tabs away from "apple" in an attempt to select it. Probably not selected?
<option>banana</option>
</div>
<input type="text">
<div role="listbox">
<option>kiwi</option> // they then eventually tab away from "kiwi", because it's the last item in the popup. Is it selected?
</div>
</div>
The Open UI Community Group just discussed Define behavior of tab key in <selectmenu> listbox
, and agreed to the following:
RESOLVED: Tab key in selectmenu listbox closes the listbox and sets focus back on the button, regardless of tabbing direction. This happens even if there is interactive content in the listbox.
Closing per today's resolution.
When the
<select>
element is open, hitting Tab closes it and puts focus back on its button.But @scottaohara pointed out in #540 that in the Chromium prototype of
<selectmenu>
, when the<selectmenu>
element is open hitting Tab does not close it, and instead moves focus to the next focusable item in the listbox (usually an<option>
).@smhigley said here:
So we should consider updating the
<selectmenu>
Tab key behavior so that it matches<select>
.When deciding this we should think about what happens with non-option focusable content in the listbox. Per #540 the platform will warn against the inclusion of this content, so it may be fine for it not to be default-keyboard-accessible; if the developer insists on inserting that content then they would be responsible for making it keyboard-accessible.