label-has-control
Angular templatesHTMLVue / SvelteVue / Sveltecorrectnessno fixdefault: offhtml/angular-eslint-recommended
What it does
Section titled “What it does”Reports a <label> that names no control: it has no for attribute (a bound [for] counts) and holds no labelable element (<input> that is not hidden, <select>, <textarea>, <button>, <meter>, <output>, <progress>).
Why it matters
Section titled “Why it matters”A label that is tied to no control labels nothing: clicking it does not focus a field and a screen reader does not read it with one. Add for with the id of the control, or put the control inside the label.
Example
Section titled “Example”...@if (ok) { <div (click)="a()" aria-hidden="true"></div> }...<div (mouseout)="a()" (blur)="b()"></div><label>Name</label><input id="a" /> <label for="a">Name</label> <label [for]="id">Name</label> <label><input /></label>...Configuration
Section titled “Configuration”angular: lint: rules: label-has-control: warn # off (default), warn, errorhtml: lint: rules: label-has-control: warn # off (default), warn, errorsvelte: lint: rules: label-has-control: warn # off (default), warn, errorvue: lint: rules: label-has-control: warn # off (default), warn, errorEnabled by the presets: html/angular-eslint-recommended.
Suppress one line with sudsy-disable-next-line label-has-control in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.
| Tool | Rule | Match | What differs |
|---|---|---|---|
| angular-eslint | label-has-associated-control |
partial | no controlComponents or labelComponents options |