click-events-have-key-events
What it does
Section titled “What it does”Reports an element with a click handler ((click), @click) and no keydown, keyup or keypress handler. Elements that a keyboard operates by themselves (links with href, buttons, form controls, <summary>, <option> and cells) and elements hidden from assistive technology or marked presentational are left alone.
Why it matters
Section titled “Why it matters”A click handler on a <div> or <span> works with a mouse only: the element takes no focus and a key press does not fire click. Keyboard and switch users cannot reach the action. Use a <button>, or add a key handler and a tabindex.
Example
Section titled “Example”<div (click)="a()"></div><div (click)="a()" (keydown.enter)="a()" tabindex="0"></div><div on-click="a()" role="presentation"></div>...<a (click)="a()" routerLink="/x">x</a><a (click)="a()">x</a><app-card (click)="a()"></app-card><div role="heading" (keydown)="a()"></div>@if (ok) { <div (click)="a()" aria-hidden="true"></div> }...Configuration
Section titled “Configuration”angular: lint: rules: click-events-have-key-events: warn # off (default), warn, errorhtml: lint: rules: click-events-have-key-events: warn # off (default), warn, errorsvelte: lint: rules: click-events-have-key-events: warn # off (default), warn, errorvue: lint: rules: click-events-have-key-events: warn # off (default), warn, errorEnabled by the presets: html/angular-eslint-recommended.
Suppress one line with sudsy-disable-next-line click-events-have-key-events in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| angular-eslint | click-events-have-key-events |
full |