Eslint-plugin-jsx-a11y: `label-has-for` doesn't pass for dynamic string values

Created on 24 Sep 2017  路  4Comments  路  Source: jsx-eslint/eslint-plugin-jsx-a11y

This causes a linter error:

<label htmlFor={`InputField-${id}`}>{labelName}</label>
<input id={`InputField-${id}`} name={id} />

id is a string passed in via props to the parent component.

Most helpful comment

Ahhh, that's what I need. Thanks!

All 4 comments

It should, because the label doesn't wrap the input.

Is that the error message you're getting?

Why does the label have to wrap the input? Shouldn't htmlFor === id pass for this rule?

The error is Form label must have associated control

For full a11y coverage, it must both be ID-linked and label-wrapped.

See the docs: if you want to configure it to require only one method (nesting vs id), or either, you can - but the default is "both".

Ahhh, that's what I need. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mikehwagz picture mikehwagz  路  4Comments

astorije picture astorije  路  3Comments

JosephNK picture JosephNK  路  4Comments

almadsen picture almadsen  路  6Comments

zargold picture zargold  路  5Comments