Dostępność
a11y/no-click-on-static
A click handler belongs on a button or link; a static element with one also needs a role, tabindex and a key handler.
poważnastatyczneWCAG 2.1.1, 4.1.2 · Afe-a11y-keyboard
Dlaczego
A div or span with a click handler cannot be reached with Tab, does not react to Enter or Space, and is announced as plain text, so keyboard and screen reader users cannot use it.
Poprawka
Use <button type="button"> for an action and <a href> for navigation; both are focusable, keyboard operable and announced correctly for free. Only when that is impossible, add role="button", tabindex="0" and a key handler that runs the action on Enter and Space.
Przykłady
// bad
<div onClick={save}>Save</div>
// good
<button type="button" onClick={save}>Save</button>Źródła
Fakty
- Identyfikator
a11y/no-click-on-static- Waga
- poważna
- Sprawdzanie
- statyczne sprawdzane w kodzie źródłowym przez
audit - Dotyczy plików
htmlangularvuesvelteastrojsx- WCAG 2.2
- 2.1.1, 4.1.2, poziom A
- Uczy jej skill
fe-a11y-keyboardKeyboard access and focus- Od wersji
- 0.1.0
Przeczytaj w terminalu
npx github:dawidolko/frontend-skills explain a11y/no-click-on-static