a11y/placeholder-label-option
Require a placeholder label option in a required select.
| Default severity | Presets | Automatic fix | Options |
|---|---|---|---|
warning |
nuxt, opinionated |
No | None |
Applies to: Vue SFC templates and blocks, with script context where the rule requires it.
Bad
The select is required, but its first option is Japan, so the form starts with a country already chosen and required never blocks submission.
<template>
<select v-model="country" required>
<option value="jp">Japan</option>
<option value="fr">France</option>
</select>
</template>
Good
An empty first option is the placeholder label option: the select starts with no value, so required makes the user pick a country.
<template>
<select v-model="country" required>
<option value="">Choose a country</option>
<option value="jp">Japan</option>
</select>
</template>
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"a11y/placeholder-label-option": "warn"
}
},
});
Then run vp run lint.