question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect report of jsx-a11y/label-has-associated-control and jsx-a11y/label-has-for

See original GitHub issue

Getting

  26:21  error  A form label must be associated with a control                                      jsx-a11y/label-has-associated-control
  26:21  error  Form label must have ALL of the following types of associated control: nesting, id  jsx-a11y/label-has-for

Even though the element is nested inside the label and the htmlfor and id are set.

                    <label htmlFor="filters">
                      Filter by
                      <select id="filters" className="form-control">
                        <option value="0" selected>
                          All Snippets
                        </option>
                        <option value="1">Featured</option>
                        <option value="2">Most popular</option>
                        <option value="3">Top rated</option>
                        <option value="4">Most commented</option>
                      </select>
                    </label>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:12
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

10reactions
teddywsicommented, May 17, 2019

I stumbled on this issue today. I’m curious if it was fully resolved? Below are some examples of code where this error is popping up for me when I don’t think it should be. I am using the latest airbnb eslint config which uses version 6.2.1 of jsx-a11y.

Select:

  <form>
    <label htmlFor="dinosaur">
      Choose a dinosaur:{' '}
      <select id="dinosaur">
        <optgroup label="Theropods">
          <option>Tyrannosaurus</option>
          <option>Velociraptor</option>
          <option>Deinonychus</option>
        </optgroup>
        <optgroup label="Sauropods">
          <option>Diplodocus</option>
          <option>Saltasaurus</option>
          <option>Apatosaurus</option>
        </optgroup>
      </select>
    </label>
  </form>

Meter:

  <form>
    <label htmlFor="fuel">
      Fuel level:{' '}
      <meter
        id="fuel"
        min={0}
        max={100}
        low={33}
        high={66}
        optimum={80}
        value={60}
      >
        at 60/100
      </meter>
    </label>
  </form>

Progress:

  <form>
    <label htmlFor="progress">
      File progress:{' '}
      <progress id="progress" max="100" value="70">
        70%
      </progress>
    </label>
  </form>
4reactions
jessebeachcommented, Nov 18, 2018

@Stopa thank you for the report. There are two things happening here.

One, there is indeed a bug. The rule doesn’t include the <select> element as one of the default control elements. You can configure the rule to include select as a controlElement for now until a future release with a fix. Here’s the fix: #503

Two, you’re example code doesn’t include a text for a label. You can use text content, or aria-label or aria-labelledby or define a prop that contains the label text and configure the rule to recognize that prop. But text you must have.

<label htmlFor="selectInput">
  Favorite ice creams
  <select id="selectInput" />
</label>
Read more comments on GitHub >

github_iconTop Results From Across the Web

label-has-associated-control documentation incorrect #457
Hi,. https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/v6.1.0/docs/rules/label-has-associated-control.md.
Read more >
How to Fix JSX-A11Y Label-Has-Associated-Control Errors
In this post we'll explore the label-has-associated-control error thrown by ESLint ... A form label must be associated with a control jsx-a11y/label-has.
Read more >
EsLint rule for label - Stack Overflow
The documentation for jsx-a11y/label-has-associated-control has a section about how to resolve this error: github.com/evcohen/eslint-plugin-jsx- ...
Read more >
eslint-plugin-jsx-a11y - npm
Why? This plugin does a static evaluation of the JSX to spot accessibility issues in React apps. Because it only catches errors in...
Read more >
Incorrect report of jsx-a11y/label-has-associated-control and ...
Incorrect report of jsx-a11y/label-has-associated-control and ... following types of associated control: nesting, id jsx-a11y/label-has-for.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found