Skip to content

fix(extract): match ARIA role attribute as a token list - #611

Open
Wang-MuFF wants to merge 2 commits into
Tencent:mainfrom
Wang-MuFF:fix/aria-role-token-list
Open

Wang-MuFF wants to merge 2 commits into
Tencent:mainfrom
Wang-MuFF:fix/aria-role-token-list

Conversation

@Wang-MuFF

Copy link
Copy Markdown

fix(extract): match ARIA role attribute as a token list

The role attribute is a space-separated token list per WAI-ARIA; the
first token is the element's effective role. Exact attribute selectors
([role="table"]) and exact string comparisons (getAttribute("role"))
miss multi-token values like role="table grid", so such containers
were rejected as non-tables and their rows/cells were not found.

  • Switch every [role="X"] selector to [role~="X"] for whitespace-token
    matching (table, grid, treegrid, list, row, cell, gridcell,
    columnheader, rowheader, rowgroup, listitem).
  • Add ariaRole() returning the first role token, mirroring the existing
    ariaSpan/ariaIndex/ariaCount helpers, and use it at the two
    presentation/none guards and two columnheader/rowheader classification
    sites so first-token semantics hold where ~= cannot express them.

Closes #595

The role attribute is a space-separated token list per WAI-ARIA; the
first token is the element's effective role. Exact attribute selectors
([role="table"]) and exact string comparisons (getAttribute("role"))
miss multi-token values like role="table grid", so such containers
were rejected as non-tables and their rows/cells were not found.

- Switch every [role="X"] selector to [role~="X"] for whitespace-token
  matching (table, grid, treegrid, list, row, cell, gridcell,
  columnheader, rowheader, rowgroup, listitem).
- Add ariaRole() returning the first role token, mirroring the existing
  ariaSpan/ariaIndex/ariaCount helpers, and use it at the two
  presentation/none guards and two columnheader/rowheader classification
  sites so first-token semantics hold where ~= cannot express them.

Closes Tencent#595
Issue Tencent#595 notes that role is a space-separated token list whose first
token is the effective role, and explicitly warns against simply switching
[role="x"] to [role~="x"]: ~= matches any token, so role="heading table"
would be misclassified as a table. Resolve the effective role (first token)
via ariaRole() and predicate-based helpers instead of CSS role selectors.

- Add isTableElement/isListElement/isRowElement/isRowgroupElement predicates
  and closestBy/selectByRole helpers, all using ariaRole() so only the
  first token decides, matching how Chromium resolves ARIA roles.
- Replace every [role~="x"] selector and the matches()/closest()/
  querySelector() call sites that used them with the matching predicate
  (table, grid, treegrid, list, row, rowgroup, cell, gridcell,
  columnheader, rowheader, listitem).
- Add regression test: role="heading table" is rejected as a non-table
  (first token "heading"), while role="table grid" is still extracted.

Closes Tencent#595

This branch has not been deployed

No deployments
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.

extract 拒绝 Chromium 已识别为 table 的合法 role token 列表

1 participant