Menu button: arrows, Escape and focus return
Enter and Space on the button already open the menu, because they fire a click on a real <button>. Arrow Up from the button opens on the last item; Escape returns focus to the button; Enter on an item runs it and closes. Letter keys (type-ahead) are left out to keep the example short: add them in Try it.
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
ArrowDown → focus: Rename
ArrowDown → focus: Duplicate
ArrowUp → focus: Rename
ArrowUp → focus: Delete
Escape → focus: Actions ▾
ArrowUp → focus: Delete
chose Delete
Enter → focus: Actions ▾