Dostępność

a11y/combobox-keyboard

A combobox keeps focus in the input, marks the highlighted option with aria-activedescendant and supports Down, Up, Enter and Escape.

poważnaręczneWCAG 2.1.1, 4.1.2 · Afe-a11y-combobox

Dlaczego

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.

Poprawka

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.

Przykłady

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)))
}

Źródła

Fakty

Identyfikator
a11y/combobox-keyboard
Waga
poważna
Sprawdzanie
ręczne ocenia człowiek; raport podaje to jako listę kontrolną
Dotyczy plików
page
WCAG 2.2
2.1.1, 4.1.2, poziom A
Uczy jej skill
fe-a11y-combobox Combobox, listbox and custom select
Od wersji
0.1.0

Plik reguły na GitHubie

Przeczytaj w terminalu

npx github:dawidolko/frontend-skills explain a11y/combobox-keyboard