a11y/form-control-has-label
Require form controls to have associated labels.
| Default severity | Presets | Automatic fix | Options |
|---|---|---|---|
warning |
happy-path, nuxt, ecosystem, opinionated |
No | None |
Applies to: Vue SFC templates and blocks, with script context where the rule requires it.
Bad
The search input has no label identifying what the user should enter.
<template>
<input type="search" />
</template>
Good
Wrapping the input in a label associates the visible Search text with the control.
<template>
<label>
Search
<input type="search" />
</label>
</template>
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"a11y/form-control-has-label": "warn"
}
},
});
Then run vp run lint.