Comments (10)
Oh, it's just a semver thing. Okay, well, that makes sense. As someone in another thread said, you're a beast. Thank you for what you do.
from eslint-plugin-jsx-a11y.
by "strict mode" do you mean, in the strict config? included configs aren't documented anywhere, you'd have to check the code: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/src/index.js#L202-L293
from eslint-plugin-jsx-a11y.
I see. I assumed the behavior was different between configs for some reason, but your link tells me that both behave exactly the same way.
Either way, I'm showing errors on a <label>
that wraps an <input>
XOR has a htmlFor
. This differs from the documented behavior:
This rule checks that any label tag (or an indicated custom component that will output a label tag) either (1) wraps an input element (or an indicated custom component that will output an input tag) or (2) has an htmlFor attribute and that the label tag has text content.
My guess is a recent pull request changed the behavior but not the documentation.
from eslint-plugin-jsx-a11y.
In which version do you see this changing? Are you using the plugin directly, or via the airbnb config?
from eslint-plugin-jsx-a11y.
I believe it traces to #457. It doesn't mention a specific commit, but I do see the same XOR verbiage in the initial documentation commit: d8ff542#diff-3ebaf3198dc642deb25323844e832cb908e0cfd2ffe0ae03578af74dae81aa81.
The rule changed at least by #759.
from eslint-plugin-jsx-a11y.
PRs don't land in order, so the important thing is to figure out if this behavior actually changed in a specific release.
from eslint-plugin-jsx-a11y.
I see the trouble now. The documentation does mention assert: "both"
, and it appears this is the default. Since assert: "both"
is in fact the correct behavior, I feel the paragraph I cited earlier should read something like
By default, this rule checks that any label tag (or an indicated custom component that will output a label tag) both (1) wraps an input element (or an indicated custom component that will output an input tag) and (2) has an htmlFor attribute and that the label tag has text content.
I'd be willing to submit a PR to this effect.
from eslint-plugin-jsx-a11y.
The default is "either", per https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/src/rules/label-has-associated-control.js#L57. This suggests that the docs are correct.
Can you share your eslint config? Something must be setting it to "both".
from eslint-plugin-jsx-a11y.
Oh, heck, you're correct. It's airbnb
. I was going to mention this in a prior comment, but got lost copy-pasting to a new one.
#718 indicates that I'm not the only one who has been caught by this. I appreciate that documentation is not the place for debate that goes into issues, but the configuration difference is buried in a different repository. I wish now that I hadn't gotten caught in this maze.
Of course a11y linting != a11y but finding disparate best practices for something so seemingly simple says something regrettable about the current state of things. But nothing I can do about that.
from eslint-plugin-jsx-a11y.
"Both" is the better and more accessible setting, so if we ever do a major version, I'll want to change the default to match.
from eslint-plugin-jsx-a11y.
Related Issues (20)
- How to configure `eslint-plugin-jsx-a11y` in `eslint.config.js` HOT 5
- [label-has-associated-control] regression - rule errors when a label does not directly have text, even if it has htmlFor HOT 22
- jsx-a11y/control-has-associated-label triggers on TD element HOT 1
- Coordinate NodeJS version support with axe-core HOT 9
- [img-redundant-alt] `words` option does not work with double-byte character words.
- `alt-text`: missing warning for empty `alt` for `<input type="image" alt="" />`
- [label-has-associated-control] Glob format not supporting labelComponents HOT 1
- Snyk: MPL 2.0 license vulnerability in axe-core HOT 2
- anchor-has-content and aria-labelledby
- Lint error on valid way for associating a `label` to an `input` control HOT 1
- Add support for ESLint 9 HOT 4
- heading-has-content false positive for object spread HOT 1
- [control-has-associated-label]: Does not allow for custom components that would result in accessible labels HOT 1
- `jsx-a11y/media-has-caption` Eslint Warning for Missing Captions in Media Elements HOT 1
- bug: type declaration for eslint flat config HOT 3
- Rule Idea: Enforce boolean literals for "booleanish" HTML attributes such as aria-hidden HOT 4
- [feat] `control-has-associated-label` can't be configured to support parent elements with label props HOT 1
- Is there a way to set all errors as warnings? HOT 1
- Upgrade `axe-core` for more features (it's pinned right now) HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eslint-plugin-jsx-a11y.