fix(template-require-mandatory-role-attributes): use axobject-query for semantic-role exemptions#2725
Draft
johanrd wants to merge 4 commits intoember-cli:masterfrom
Draft
Conversation
614446f to
5cf4879
Compare
3ff7f86 to
cf9f552
Compare
…or semantic-role exemptions
Replaces the 3-entry hand-list (`{input type}:{role}` pairings) with a
lookup against axobject-query's `elementAXObjects` + `AXObjectRoles`
maps. Mirrors the approach used by eslint-plugin-jsx-a11y (its
`isSemanticRoleElement` util) and @angular-eslint/template.
## Why
The hand-list covered 3 pairings: `checkbox:checkbox`, `checkbox:switch`,
`radio:radio`. axobject-query encodes substantially more — including
`input[type=range]:slider`, `input[type=number]:spinbutton`,
`input[type=text]:textbox`, `input[type=search]:searchbox`. Each of
these is a case where the native element already provides the role's
required ARIA state (e.g., `<input type=range>` provides value via its
native `value` attribute, satisfying `role=slider`'s `aria-valuenow`
requirement).
Using axobject-query directly:
- Gives us strict superset coverage of the hand-list.
- Stays in sync when axobject-query updates (the hand-list had already
drifted — the earlier revision incorrectly claimed menuitemcheckbox
/ menuitemradio pairings were in axobject-query when they aren't).
- Matches jsx-a11y / angular-eslint behavior, closing a documented
parity gap.
Adds `axobject-query@^4.1.0` as a direct dep. It's already a transitive
dep via other ecosystem packages; this elevates it to first-class.
## Changes
- `lib/rules/template-require-mandatory-role-attributes.js` — replace
`NATIVELY_CHECKED_INPUT_ROLE_PAIRS` + `isNativelyChecked` with
`isSemanticRoleElement` that walks `elementAXObjects` and checks
`AXObjectRoles`. Handles both `GlimmerElementNode` (angle-bracket
syntax) and `GlimmerMustacheStatement` (classic `{{input}}` helper).
- `package.json` — add `axobject-query@^4.1.0`.
- `tests/lib/rules/template-require-mandatory-role-attributes.js` —
add tests for the broadened coverage (`<input type=range role=slider>`
now valid in both gts and hbs forms).
- `docs/rules/template-require-mandatory-role-attributes.md` — rewrite
the exemption section to describe the axobject-query-backed lookup
with a table of known pairings.
cf9f552 to
ff35fa6
Compare
…imary source axobject-query is the data package the rule queries, but the normative source for "native <input type=checkbox> exposes aria-checked via the checked IDL attribute" is HTML-AAM §el-input-checkbox. Adding the HTML-AAM link makes the exemption's spec grounding explicit instead of leaving axobject-query as a free-floating data source.
This was referenced Apr 22, 2026
f735a42 to
48ef43c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Premise
Per WAI-ARIA APG and HTML-AAM, a native HTML element that implements a given ARIA role implicitly supplies that role's required ARIA state. Classic example:
<input type="checkbox" role="switch">— the nativecheckedattribute provides thearia-checkedstate thatrole="switch"requires. Authors shouldn't need to addaria-checkedredundantly.Problem
The rule flags any element with a role missing required ARIA attributes, including patterns where the native element already provides the state.
<input type="checkbox" role="switch">is flagged for missingaria-checked— a documented false positive.Fix
Consult
axobject-query'selementAXObjects+AXObjectRolesmaps to determine when a native element satisfies a given role, mirroringeslint-plugin-jsx-a11y'sisSemanticRoleElement. When the pair matches, skip the missing-attribute check for that role.Adds
axobject-query@^4.1.0as a direct dependency. It's already installed as a transitive dep across the ecosystem; elevates to first-class.Coverage (non-exhaustive)
<input type="checkbox">checkbox,switchcheckedstate<input type="radio">radiocheckedstate<input type="range">slidervalue/min/max<input type="number">spinbuttonvalue(no required ARIA)<input type="text">textbox<input type="search">searchboxBoth angle-bracket syntax (
<input type="checkbox" role="switch">) and the classic{{input type="checkbox" role="switch"}}helper are handled.Undocumented pairings still flag
<input type="checkbox" role="menuitemcheckbox">/<input type="radio" role="menuitemradio">etc. — axobject-query doesn't list these, so they remain flagged for missingaria-checked. Matches jsx-a11y and angular-eslint behavior.Why not keep the hand-list?
An earlier revision of this PR hand-maintained a 3-entry
{input type}:{role}whitelist. Audit-time review showed:menuitemcheckbox/menuitemradiopairings that axobject-query doesn't actually encode. A hand-list encodes the maintainer's (imperfect) understanding of the library's data; using the library directly eliminates the drift class.Prior art
role-has-required-aria-propsisSemanticRoleElement(type, attributes)via axobject-query'selementAXObjectsrole-has-required-ariarole-has-required-aria-props{role: switch, type: checkbox}only — much narrower than axobject-queryrole-has-required-aria-attrsThis PR aligns with jsx-a11y / angular-eslint on the axobject-query-backed approach. vue-a11y's narrower carve-out and lit-a11y's no-exemption behavior are documented divergences.
What this PR does not fix
Role-token case-insensitivity at the rule level —
<input type="checkbox" role="SWITCH">is silently ignored (aria-query'sroles.get(role)is case-sensitive, so the rule short-circuits to null before reaching theisSemanticRoleElementcheck). That rule-wide gap is addressed in #2728.Audit fixture
Translated peer-plugin test fixture at
tests/audit/role-has-required-aria/peer-parity.js. Not wired into the default test run.