Skip to content

fix(aria): read role tokens and aria state values case-insensitively - #43680

Closed
JohnnyXu (xubenqiang) wants to merge 1 commit into
microsoft:mainfrom
xubenqiang:fix/aria-case-values
Closed

JohnnyXu (xubenqiang) wants to merge 1 commit into
microsoft:mainfrom
xubenqiang:fix/aria-case-values

Conversation

@xubenqiang

Copy link
Copy Markdown

Fixes #43662

ARIA role tokens and the enumerated state values (aria-checked, aria-pressed, aria-expanded, aria-readonly, aria-invalid) are ASCII case-insensitive, but packages/injected/src/roleUtils.ts compared them with exact strings. So:

  • role="Button" was not a button at all (it fell through to the implicit role / text),
  • aria-checked="True", aria-pressed="True" and aria-expanded="True" read as false,
  • aria-readonly="True" read as not readonly,
  • aria-invalid="Spelling" fell back to true instead of spelling.

getByRole, role= selectors and the aria snapshot therefore disagreed with what Chromium exposes for the same DOM.

Change

packages/injected/src/roleUtils.ts

  • getExplicitAriaRole: lowercase the role tokens before matching.
  • getChecked, getAriaPressed, getAriaExpanded: lowercase the attribute value before comparing (the mixed / undefined cases are unchanged).
  • getReadonly, getAriaInvalid: same normalisation.

Test

tests/page/selectors-role.spec.ts — SE-052b should match mixed-case role tokens and aria state values: three elements with role="checkbox" aria-checked="True", role="Button" aria-pressed="True" and role="button" aria-expanded="True"; asserts role=checkbox[checked], getByRole('checkbox', { checked: true }), getByRole('button') (2), pressed: true, expanded: true, and the aria snapshot ([checked], [pressed], [expanded], button "bold").

Verified red/green on Windows 11 with the bundled chromium:

  • without the change: the test fails with Expected: 1, Received: 0 (the first role=checkbox[checked] assertion);
  • with it: tests/page/selectors-role.spec.ts on chromium-page — 22 passed.

ARIA role tokens and the enumerated state values (`aria-checked`,
`aria-pressed`, `aria-expanded`, `aria-readonly`, `aria-invalid`) are ASCII
case-insensitive, but the injected role engine compared them with exact
strings. `role="Button"` was therefore not a button at all, and
`aria-checked="True"` / `aria-pressed="True"` read as false, so
`getByRole` and the aria snapshot disagreed with what Chromium exposes.
Copilot AI balanced review requested due to automatic review settings October 27, 2026 17:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: aria-checked="True" and other mixed-case role / ARIA values are treated as false

3 participants