Accessibility
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.
seriousstaticWCAG 2.1.1, 4.1.2 · Afe-a11y-keyboard
Why
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.
Fix
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.
Examples
// bad
<div onClick={save}>Save</div>
// good
<button type="button" onClick={save}>Save</button>Sources
Facts
- Id
a11y/no-click-on-static- Severity
- serious
- Check
- static checked in the source by
audit - Applies to
htmlangularvuesvelteastrojsx- WCAG 2.2
- 2.1.1, 4.1.2, level A
- Taught by the skill
fe-a11y-keyboardKeyboard access and focus- Since version
- 0.1.0
Read it in the terminal
npx github:dawidolko/frontend-skills explain a11y/no-click-on-static