Eslint-plugin-jsx-a11y: false positive "A form label must be associated with a control"

Created on 25 Nov 2020  路  3Comments  路  Source: jsx-eslint/eslint-plugin-jsx-a11y

I'm using airbnb eslint configuration, and eslint complains when input's label is wrapped in another element:

function App() {
  return (
    <form>
      <h2>
        <label htmlFor="new-todo-input">
          What needs to be done?
        </label>
      </h2>
      <input
        type="text"
        id="new-todo-input"
        name="text"
      />
    </form>
  );
}

I'm getting this error during compilation:

Failed to compile.
src\App.jsx
  Line 5:9:  A form label must be associated with a control  jsx-a11y/label-has-associated-control

Most helpful comment

Thanks @ljharb I C this has come up in the past.

All 3 comments

image
Me 2.

This isn't a false positive. The airbnb config requires that every input be BOTH for-id linked, and also the input nested inside the label.

Thanks @ljharb I C this has come up in the past.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lencioni picture lencioni  路  5Comments

mikehwagz picture mikehwagz  路  4Comments

almadsen picture almadsen  路  6Comments

calinoracation picture calinoracation  路  3Comments

AlmeroSteyn picture AlmeroSteyn  路  5Comments