Skip to content
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

Implicit role mapping for <th> element #1012

Open
jlp-craigmorten opened this issue Nov 11, 2023 · 1 comment
Open

Implicit role mapping for <th> element #1012

jlp-craigmorten opened this issue Nov 11, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@jlp-craigmorten
Copy link
Contributor

Currently the getRole(element: Element): string | null method returns "columnheader" for the th element which isn't always the correct choice for the element depending on ancestory and attributes.

REF: https://github.com/eps1lon/dom-accessibility-api/blob/main/sources/getRole.ts#L62


According to html-aria:

role=columnheader, rowheader or cell if the ancestor table element is exposed as a role=table

role=columnheader, rowheader or gridcell if the ancestor table element is exposed as a role=grid or treegrid

No corresponding role if the ancestor table element is not exposed as a role=table, grid or treegrid

Here I appreciate hands may be tied less the scope of getRole() is expanded to start exploring parent elements.


According to html-aam:

If scope="row" then map th to rowheader
If scope="col" then map th to columnheader

Which does appear to be more achievable for this library as we have similar precedent for mapping roles from a combination of local name and attribute value(s) in the implicit role switch statement flow.

Propose that the th logic is moved out of the localNameToRoleMappings map and it's role is instead calculated dynamically as:

  1. rowheader if scope="row"
  2. columnheader if scope="col"
  3. TBD if otherwise, i.e. if scope is one of rowgroup, colgroup, or missing (REF: https://www.w3.org/TR/2011/WD-html5-author-20110809/the-th-element.html#attr-th-scope-auto)

As an aside, also raised w3c/html-aria#495 to query why html-aria does not mention the implicit role logic when the scope attribute is present.

@gnpivo
Copy link

gnpivo commented Jul 17, 2024

Here is a version that covers all five possible cases

role=cell if the th element is not a column header, row header, column group header or row group header and the ancestor table element is exposed as a role=table

role=gridcell if the th element is not a column header, row header, column group header or row group header and the ancestor table element is exposed as a role=grid or treegrid

role=columnheader if the th element is a column header or column group header and the ancestor table element is exposed as a role=table, grid or treegrid

role=rowheader if the th element is a row header or row group header and the ancestor table element is exposed as a role=table, grid or treegrid

No corresponding role if the ancestor table element is not exposed as a role=table, grid or treegrid

@eps1lon eps1lon added the bug Something isn't working label Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants