a11y/no-autofocus
Disallow the use of the autofocus attribute
Default severity: warning
Presets: happy-path, nuxt, ecosystem, opinionated
Automatic fix: None; review the suggested change
Applies to: Vue SFC templates and blocks, with script context where the rule requires it
Options: No rule-specific options. Severity and preset selection are configurable.
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({
lint: {
vize: {
"preset": "incremental",
"rules": {
"a11y/no-autofocus": "warn"
}
},
},
});
vp run lint
Bad
The input requests automatic focus when it appears.
<template>
<input autofocus name="query" />
</template>
Good
Removing autofocus avoids this automatic focus request while retaining the query input.
<template>
<input name="query" />
</template>
Good avoids this rule's finding under the configuration above; other rules may still report diagnostics.