Accessibility
a11y/combobox-keyboard
A combobox keeps focus in the input, marks the highlighted option with aria-activedescendant and supports Down, Up, Enter and Escape.
seriousmanualWCAG 2.1.1, 4.1.2 · Afe-a11y-combobox
Why
If focus jumps into the list, typing stops working; if the highlight is only a CSS class, a screen reader never says which suggestion is active, and the person cannot pick one.
Fix
Keep DOM focus in the input. Down Arrow opens the list and moves the highlight; Up Arrow moves back; Enter accepts and closes; Escape closes (a second Escape may clear); Alt+Down opens without moving. Set aria-activedescendant on the input to the highlighted option's id and aria-selected="true" on that option. Announce the number of results in a polite live region after typing pauses.
Examples
input.addEventListener('keydown', (e) => {
if (e.key === 'ArrowDown') { open(); highlight(active + 1) }
if (e.key === 'Escape') close()
})
function highlight(i) {
input.setAttribute('aria-activedescendant', options[i].id)
options.forEach((o, j) => o.setAttribute('aria-selected', String(i === j)))
}Sources
Facts
- Id
a11y/combobox-keyboard- Severity
- serious
- Check
- manual a person reviews it; the report lists it as a checklist
- Applies to
page- WCAG 2.2
- 2.1.1, 4.1.2, level A
- Taught by the skill
fe-a11y-comboboxCombobox, listbox and custom select- Since version
- 0.1.0
Read it in the terminal
npx github:dawidolko/frontend-skills explain a11y/combobox-keyboard