-
-
Notifications
You must be signed in to change notification settings - Fork 641
Flag aria-label and aria-labelledby on non-interactive elements
#911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flag aria-label and aria-labelledby on non-interactive elements
#911
Conversation
Codecov Report
@@ Coverage Diff @@
## main #911 +/- ##
=======================================
Coverage 99.29% 99.30%
=======================================
Files 103 105 +2
Lines 1570 1574 +4
Branches 514 514
=======================================
+ Hits 1559 1563 +4
Misses 11 11
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
|
I’m stumped about why the Node.js ≤11 checks are failing (example failing run). I didn’t change the 689 /home/runner/work/eslint-plugin-jsx-a11y/eslint-plugin-jsx-a11y/node_modules/language-tags/lib/Tag.js:17
690 static ERR_DEPRECATED = 1;
691 ^
692
693 SyntaxError: Unexpected token =
694
695 9 |
696 10 | import { propName, getLiteralPropValue } from 'jsx-ast-utils';
697 > 11 | import tags from 'language-tags';
698 | ^
699 12 | import { generateObjSchema } from '../util/schemas';
700 13 | import getElementType from '../util/getElementType';
701 14 |
702
703 at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
704 at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
705 at Object.<anonymous> (node_modules/language-tags/lib/index.js:11:11)
706 at Object.<anonymous> (src/rules/lang.js:11:1)
707 at Object.<anonymous> (__tests__/src/rules/lang-test.js:12:1) |
|
@smockle thank you for the initiative here. As a matter of principle, we don't want to store knowledge of WAI-ARIA in this plugin. That knowledge should be stored in By doing so, we can leverage a store of all elements that map to specific roles. For example, there are 19 HTML elements that map to the The big complication here is that there is no constant indicator that determines if a role supports a label. Some interactive and some non-interactive roles will support a label and some roles have it outright prohibited. We get at this inconsistently right now with the Once we plumbed that data through |
Got it! This makes sense from an architecture perspective. Thanks for explaining, @jessebeach! I’ll close this PR, since its approach isn’t aligned with this. 👍 Out of curiosity, two related questions:
|
This is a good callout; I’d forgotten about cases like |
This code is a vestige of the project before
Exactly, the attributes define the shape of the concept, when attributes are required to match a role. You can see this in the AX Tree when using the Inspector in Chrome. Many HTML elements look "semantic", but if they don't have a mapping to an AX Tree Node, then they have no semantic expression exposed to clients. That's what this tech stack is meant to formalize -- the reality of the semantic mappings from HTML ( |


What does this PR accomplish?
Fixes #910
This PR indicates an error in markup like
<span aria-label="Hello, world!">Hello</span>.Why?
spananddivelements implicitly have thegenericrole, andgenericprohibitsaria-labelandaria-labelledby.From the
genericrole spec:Implementation details
Previously, neither
divnorspanhad an implicitly role defined insrc/util/implicitRoles/, so the codepath in src/rules/role-supports-aria-props.js#L55-L63 was taken, which “assume[s] that the element can handle the global set of aria-* properties.” This is not a correct assumption, so I addedsrc/util/implicitRoles/div.jsandsrc/util/implicitRoles/span.jsand re-exported them from thesrc/util/implicitRoles/index.jsbarrel.Once the src/rules/role-supports-aria-props.js#L65-L70 codepath was taken, I discovered that the list of a role’s
prohibitedPropswas unused, so I concatenated it to the existing list ofinvalidAriaPropsForRole.Next, I discovered that the list of
validTests, tests expected to pass without errors, included e.g.<div role="superscript" aria-label />. This initially confused me, sincearia-labelis one ofsuperscript’sprohibitedProps. I traced this to the superclass—roletypeincludesaria-label—then added a filter to remove them.Finally, the addition of
src/util/implicitRoles/div.jsbroke a few role-related tests that assumeddivwould not have an explicit or implicit role. I replaceddivwith a made-up custom element namedcustom-element, which functions the waydivdid before this PR (i.e. lacking explicit and implicit roles).Testing details
I ran
npm testlocally, and all tests pass: