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.

label-has-associated-control failing for correct structure

See original GitHub issue

Looks like updating to 17.1.0 enables label-has-associated-control but it seems to be failing for a correct label/input. To my understanding, the correct structure could either be a nested input within a label OR use the htmlFor prop with a valid DOM ID.

In this case, we’re using htmlFor:

const Foo () => {
  return (
        <label htmlFor="filterAll">
          ...
        </label>
        <input id="filterAll" />
  )
}

and the linter is giving us the following error

error A form label must be associated with a control jsx-a11y/label-has-associated-control

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:16
  • Comments:9

github_iconTop GitHub Comments

67reactions
ljharbcommented, Aug 15, 2018

No, our config requires both - not either.

To cover 100% of browsers and assistive devices, the input must BOTH be nested inside the label and also be for/ID-linked to it.

13reactions
bteng22commented, Aug 15, 2018

Ahh I see thanks for the clarification @ljharb — does this warrant a change in the documentation here? https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/label-has-associated-control.md where it sounds as though either method is supported. Maybe my understanding of how these two packages relate is skewed.

Or is there an option similar to the deprecated jsx-a11y/label-has-for where either rule is accepted? i.e.

"jsx-a11y/label-has-for": [ 2, {
  "required": {
      "some": [ "nesting", "id" ]
  }
}]

Doesn’t seem to look like it based on the docs referenced above.

Thanks again in advance!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix JSX-A11Y Label-Has-Associated-Control Errors
There are two solutions to relating the label to an input: Wrap an input component inside the label. Adding an input and relating...
Read more >
<input>: The Input (Form Input) element - HTML
The <input> HTML element is used to create interactive controls for web-based forms in order to accept data from the user; a wide...
Read more >
Docs • Svelte
Complete documentation for Svelte.
Read more >
Understanding Success Criterion 1.3.1 - W3C
Sighted users perceive structure and relationships through various visual ... H44: Using label elements to associate text labels with form controls (HTML).
Read more >
Well-Known Labels, Annotations and Taints - Kubernetes
The control plane adds this annotation to an Endpoints object if the associated Service has more than 1000 backing endpoints. The annotation ...
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