I have this component:
// @flow
import React, { Element } from 'react';
import styles from './Label.scss';
import cs from 'classnames';
export const Label = ({
id,
htmlFor,
invalid,
required,
children
}: {
id: string,
htmlFor: string,
invalid: boolean,
required: boolean,
children: Element<*>
}) =>
<label
htmlFor={htmlFor}
id={id}
required={required}
className={cs(
styles.label,
required ? styles.required : '',
invalid ? styles.invalid : ''
)}
>
{children}
</label>;
Label.displayName = 'Label';
When I run eslint I get this error message even though there is an htmlFor
:
error: Form label must have associated control (jsx-a11y/label-has-for) at packages/ds-component-library/src/components/atoms/Label/Label.js:19:3:
In your .eslintrc, try the following:
"rules": {
"jsx-a11y/label-has-for": [ 2, {
"components": [ "Label" ],
"required": {
"some": [ "nesting", "id" ]
},
"allowChildren": false,
}]
}
This is coming from: https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/label-has-for.md
Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With