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

*ByRole() accessible name is incorrect for nested element with a title attribute #903

Closed
nandastone opened this issue Feb 25, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@nandastone
Copy link

  • @testing-library/react version: 9.2.0
  • Testing Framework and version: codesandbox.io Jest
  • DOM Environment:

Relevant code or config:

<th>
  <span title="Test title">Animal</span>
</th>
const columnHeader = screen.getByRole("columnheader", {
  name: /Animal/i
});

Test output:

Unable to find an accessible element with the role "columnheader" and name `/Animal/i`

Here are the accessible roles:
--------------------------------------------------
  columnheader:

  Name "Test title":
  <th />

What you did:

Attempt to select a column heading by role, using the element text as the accessible name.

What happened:

react-testing-library determines the accessible name as the title attribute of the <span /> element wrapping the element text. Testing across various browsers determines the accessible name should in fact be the element text.

CleanShot 2021-02-25 at 11 00 38

CleanShot 2021-02-25 at 10 59 36

Reproduction:

https://codesandbox.io/s/react-testing-library-demo-forked-1xe1w?file=/src/__tests__/hello.js

Problem description:

I wrap my column headings in <span title="" /> to provide tooltips. Instead of selecting the column heading by the text visible to the end user, I need to use tooltip text which is not yet visible.

Suggested solution:

Mirror browser calculation of the accessible name, or at least provide a way to configure how the name is matched in byRole().

@eps1lon
Copy link
Member

eps1lon commented Feb 25, 2021

Transferring to eps1lon/dom-accessibility-api#554 since that package is responsible for the calculation

@eps1lon eps1lon closed this as completed Feb 25, 2021
@eps1lon eps1lon added the bug Something isn't working label Feb 25, 2021
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

2 participants