Skip to content

click-events-have-key-events

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.

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.

Reported
<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> }
...
angular:
lint:
rules:
click-events-have-key-events: warn # off (default), warn, error
html:
lint:
rules:
click-events-have-key-events: warn # off (default), warn, error
svelte:
lint:
rules:
click-events-have-key-events: warn # off (default), warn, error
vue:
lint:
rules:
click-events-have-key-events: warn # off (default), warn, error

Enabled 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.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
angular-eslint click-events-have-key-events full