Repository navigation
ComboboxOption - tab navigation for accessibility #3729
Replies: 1 comment
|
In a single-select Combobox, Tab commits the active option after arrow-key navigation. Escape followed by Tab already gives you a way to leave without committing. To get that behavior with one Tab keystroke, I used a capture handler on the input and a non-modal list. <ComboboxInput
onKeyDownCapture={(event) => {
if (
event.key === "Tab" &&
event.currentTarget.getAttribute("aria-expanded") === "true"
) {
event.stopPropagation();
}
}}
/>
<ComboboxOptions modal={false}>
{/* Your existing ComboboxOption elements */}
</ComboboxOptions>The capture handler keeps Headless UI's keydown handler from committing the option. Leaving the browser's default action in place lets it move focus. The I tested with |
Uh oh!
There was an error while loading. Please reload this page.
Hello,
first of all - thank you very much for the great UI components!!
I use the @headlessui/react library in my project and at the moment accessibility is a huge topic in the European Union (because of a new strict law).
I use the Combobox with ComboboxInput, ComboboxOptions and finally ComboboxOption as={Fragment}.
It works really well to access the search result with key down (and up) and to select an entry with Enter.
My problem is, when an result item was selected in the opened combobox by key down and the user interacts with "tab", the item is selected (like also mentioned in the documentation). In my opinion this is not the expected behaviour - if you want to select an item, you use "Enter" on the keyboard. With "tab" you want to change to the next tab selectable item outside of the combobox.
Is there a way to change this? It is not a solution for me to just prevent the default behaviour, because then you cannot navigate with tab out of the combobox any longer.
Would be great if somebody can help me or if there will be an option from the Combobox to handle this different.
thx :)
All reactions