label-has-associated-control failing for correct structure
See original GitHub issueLooks like updating to 17.1.0
enables label-has-associated-control
but it seems to be failing for a correct label/input. To my understanding, the correct structure could either be a nested input
within a label OR use the htmlFor
prop with a valid DOM ID.
In this case, we’re using htmlFor
:
const Foo () => {
return (
<label htmlFor="filterAll">
...
</label>
<input id="filterAll" />
)
}
and the linter is giving us the following error
error A form label must be associated with a control jsx-a11y/label-has-associated-control
Issue Analytics
- State:
- Created 5 years ago
- Reactions:16
- Comments:9
Top Results From Across the Web
How to Fix JSX-A11Y Label-Has-Associated-Control Errors
There are two solutions to relating the label to an input: Wrap an input component inside the label. Adding an input and relating...
Read more ><input>: The Input (Form Input) element - HTML
The <input> HTML element is used to create interactive controls for web-based forms in order to accept data from the user; a wide...
Read more >Understanding Success Criterion 1.3.1 - W3C
Sighted users perceive structure and relationships through various visual ... H44: Using label elements to associate text labels with form controls (HTML).
Read more >Well-Known Labels, Annotations and Taints - Kubernetes
The control plane adds this annotation to an Endpoints object if the associated Service has more than 1000 backing endpoints. The annotation ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No, our config requires both - not either.
To cover 100% of browsers and assistive devices, the input must BOTH be nested inside the label and also be for/ID-linked to it.
Ahh I see thanks for the clarification @ljharb — does this warrant a change in the documentation here? https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/label-has-associated-control.md where it sounds as though either method is supported. Maybe my understanding of how these two packages relate is skewed.
Or is there an option similar to the deprecated
jsx-a11y/label-has-for
where either rule is accepted? i.e.Doesn’t seem to look like it based on the docs referenced above.
Thanks again in advance!