Skip to content

no-autofocus

Reports an element with an autofocus attribute (or a bound [autofocus] on an HTML element; on a component it is one of its inputs). One inside a <dialog> is left alone.

Moving focus when a page loads skips the content before it: a screen reader user hears the page from the middle, and a sighted keyboard user loses the place. Let the user choose where to start.

Reported
...
<a [innerHTML]="html"></a> <a><img alt="x" /></a> <a aria-label="x"></a> <a>{{ x }}</a>
<input autofocus />
<dialog><input autofocus /></dialog>
<mat-sidenav [autoFocus]="x"></mat-sidenav> <input [autofocus]="y" />
...
angular:
lint:
rules:
no-autofocus: warn # off (default), warn, error
html:
lint:
rules:
no-autofocus: warn # off (default), warn, error
svelte:
lint:
rules:
no-autofocus: warn # off (default), warn, error
vue:
lint:
rules:
no-autofocus: warn # off (default), warn, error

Enabled by the presets: html/angular-eslint-recommended.

Suppress one line with sudsy-disable-next-line no-autofocus 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 no-autofocus full