click-events-have-key-events
Configuration
rslint.config.ts
Rule Details
Enforce that a visible, non-interactive element with an onClick handler
also declares at least one keyboard event listener (onKeyDown,
onKeyUp, or onKeyPress). Pairing a pointer event with a keyboard
counterpart keeps the interaction reachable for keyboard-only users and
assistive technologies.
The rule reports a JSX opening element when all of the following hold:
- The resolved element name is in the HTML DOM set (custom React components are skipped — the rule does not know what low-level element they render).
- The element is not hidden from screen readers (no
aria-hidden={true}/aria-hidden="true", not an<input type="hidden">). - The
roleattribute, when statically a literal string, is notpresentationornone. - The element is not inherently interactive (e.g.
<button>,<a href>,<select>,<input type="text">). - The element declares an
onClickattribute (case-insensitively, value irrelevant — boolean form,null,undefinedall count as present). - The element declares none of
onKeyDown,onKeyUp,onKeyPress(case-insensitively, as a direct attribute — spread attributes are opaque).
This rule takes no arguments.
Examples of incorrect code for this rule:
Examples of correct code for this rule: