jsx-a11y/label-has-for
eslint-plugin-jsx-a11y
import jsxA11y from "eslint-plugin-jsx-a11y";
export default [
{
plugins: { "jsx-a11y": jsxA11y },
rules: {
"jsx-a11y/label-has-for": "error",
},
},
];This rule is deprecated. Check its documentation for a replacement before enabling it.
Enforce that <label> elements have the htmlFor prop.
<label>{children}</label>function Foo(props) {
return <label {...props} />
}<input type="text" id="firstName" />
<label>First Name</label>function Foo({ htmlFor, ...props}) {
return <label htmlFor={htmlFor} {...props} />
}
// OR
function Foo(props) {
const {
htmlFor,
...otherProps
} = props;
return <label htmlFor={htmlFor} {...otherProps} />
}<label htmlFor="firstName">
<input type="text" id="firstName" />
First Name
</label>Examples from the ESLint documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
jsx-a11y/label-has-for
eslint-plugin-jsx-a11y
import jsxA11y from "eslint-plugin-jsx-a11y";
export default [
{
plugins: { "jsx-a11y": jsxA11y },
rules: {
"jsx-a11y/label-has-for": "error",
},
},
];Oxlint does not have this rule.
a11y/noLabelWithoutControl
a11y · since 1.8.0
{
"linter": {
"rules": {
"a11y": {
"noLabelWithoutControl": "error"
}
}
}
}Enforce that a control (an interactive element) has a text label.
Enforces using semantic DOM elements over the ARIA role property.
Disallow aria-hidden="true" from being set on focusable elements.
Enforce <a> text to not exactly match "click here", "here", "link", or "a link".
Non-interactive elements should not be assigned mouse or keyboard event listeners.