no-autofocus
Angular templatesHTMLVue / SvelteVue / Sveltecorrectnessno fixdefault: offhtml/angular-eslint-recommended
What it does
Section titled “What it does”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.
Why it matters
Section titled “Why it matters”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.
Example
Section titled “Example”...<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" />...Configuration
Section titled “Configuration”angular: lint: rules: no-autofocus: warn # off (default), warn, errorhtml: lint: rules: no-autofocus: warn # off (default), warn, errorsvelte: lint: rules: no-autofocus: warn # off (default), warn, errorvue: lint: rules: no-autofocus: warn # off (default), warn, errorEnabled 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.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| angular-eslint | no-autofocus |
full |