Combobox: focus stays in the input, aria-activedescendant moves
Focus never leaves the input, so typing always works; the highlighted option is announced through aria-activedescendant. onMouseDown with preventDefault stops the input from blurring (and closing the list) before an option's click fires. Escape closes an open list; pressed again on a closed list, it clears the field. A production combobox needs more (scrolling the active option into view, result counts in a live region), which is why libraries exist.
Dialogs, disclosures, tabs, menu buttons and comboboxes each have a standard keyboard pattern in the WAI-ARIA Authoring Practices; build them with the right roles, states and keys, prefer native elements where they exist, and reach for a tested headless library for the hard ones.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 6 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write an accessible Accordion from three disclosures where opening one closes the others.
Add Home and End support to the menu button example.
Explain it without notes
Describe the keyboard interaction of the WAI-ARIA tabs pattern and how roving tabindex implements it in React.
When would you use a disclosure, a menu button and a combobox? Give a native alternative for each where one exists.
Why does a combobox use aria-activedescendant instead of moving focus into the list?
What does a headless component library give you, and name two.
Preview
Console
Nothing logged yet.Expected console output
type a | expanded: true | active: - | value: a | focus on input: true
ArrowDown | expanded: true | active: Apple | value: a | focus on input: true
ArrowDown | expanded: true | active: Apricot | value: a | focus on input: true
Enter | expanded: false | active: - | value: Apricot | focus on input: true
Escape | expanded: false | active: - | value: | focus on input: true