react-a11y
Version:
Warns about potential accessibility issues with your React elements.
35 lines (22 loc) • 717 B
Markdown
Enforce label tags have `htmlFor` attribute. Form controls using a `label` to
identify them must have only one label that is programmatically associated with
the control using: `<label htmlFor={/* ID or name of control*/}>...</label>`.
*This rule takes no options*
```jsx harmony
// passes when the label is hidden
<label aria-hidden="true"></label>
// passes when the label has a valid `htmlFor` prop
<label for="foo"></label>
// passes when it is not a label
<div></div>
```
```jsx harmony
// fails when a label is not hidden and has no `htmlFor`
<label></label>
```
- [This document](https://www.w3.org/WAI/tutorials/forms/labels) from w3.org