eslint-plugin-jsx-a11y: Incorrect report of jsx-a11y/label-has-associated-control and jsx-a11y/label-has-for
Getting
26:21 error A form label must be associated with a control jsx-a11y/label-has-associated-control
26:21 error Form label must have ALL of the following types of associated control: nesting, id jsx-a11y/label-has-for
Even though the element is nested inside the label and the htmlfor and id are set.
<label htmlFor="filters">
Filter by
<select id="filters" className="form-control">
<option value="0" selected>
All Snippets
</option>
<option value="1">Featured</option>
<option value="2">Most popular</option>
<option value="3">Top rated</option>
<option value="4">Most commented</option>
</select>
</label>
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 12
- Comments: 15 (5 by maintainers)
I stumbled on this issue today. I’m curious if it was fully resolved? Below are some examples of code where this error is popping up for me when I don’t think it should be. I am using the latest airbnb eslint config which uses version 6.2.1 of jsx-a11y.
Select:
Meter:
Progress:
@Stopa thank you for the report. There are two things happening here.
One, there is indeed a bug. The rule doesn’t include the
<select>element as one of the default control elements. You can configure the rule to includeselectas acontrolElementfor now until a future release with a fix. Here’s the fix: #503Two, you’re example code doesn’t include a text for a label. You can use text content, or
aria-labeloraria-labelledbyor define a prop that contains the label text and configure the rule to recognize that prop. But text you must have.Tweaking the airbnb config did the trick, thank you guys!
@rpellerin @codebycliff how is your rule configured? For example, the airbnb config requires both nesting and id-linking.
@greypants it will be, but doing so is a breaking change - a soft deprecation is not.
Sounds good. Consider my portion of this issued resolved.
@ljharb Thanks, that seems to be the reason in my case as I am using the airbnb config!
+1
Also ran in this issue, though newest version of the plugin 6.1.1 is installed!
Occurs in combination with React 16.4.2 and eslint 5.4.0 / eslint-plugin-react 7.11.0