eslint-plugin-jsx-a11y: control-has-associated-label error with label/input?
We are getting linting errors with this rule for simple JSX such as:
<label htmlFor="foo">Foo</label>
<input id="foo" type="text" />
// or
<label>
Foo
<input type="text" />
</label>
Both result in Error: A control must be associated with a text label jsx-a11y/control-has-associated-label
Our rule is setup as:
'jsx-a11y/control-has-associated-label': 'error',
Do we need to pass the second argument object to the rule? or should this be supported out of the box?
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 13
- Comments: 40 (19 by maintainers)
This is the closest I got to what I wanted (either label nests form element or uses htmlFor):
Unfortunately it doesn’t complain if you don’t use any Label at all for a form element… but it seems the be the same with the default eslint…
cc @jessebeach - this rule might need the same “assert” options as the inverse rule.
This is what I had to add to get either htmlFor or nesting:
Definitely will do. Let me try manually setting the depth first so I don’t create an issue that immediately closes X-D
EDIT: It appears the default depth I’m working with is 25. I’ll create a new issue.
We are having this warning thrown up as well:
==>
37:5 error A form label must be associated with a control jsx-a11y/label-has-associated-controlFor now, we’re turning off the
jsx-a11y/label-has-associated-controlrule.Whoops, i think i misunderstood from the start 😃 your code seems correct.
Yes that’s for ‘label-has-associated-control’, not ‘control-has-associated-label’ which is what I’m talking about 🙂