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

Support list and listitem #233

Closed
Raynos opened this issue May 13, 2020 · 4 comments
Closed

Support list and listitem #233

Raynos opened this issue May 13, 2020 · 4 comments

Comments

@Raynos
Copy link

Raynos commented May 13, 2020

I tried to use dom testing library with getByRole('listitem', { name: 'text' })

I realized that querying a button by accessibility name works but the function computeAccessibleName when called on <span role='listitem'>text</span> returns empty string

@eps1lon
Copy link
Owner

eps1lon commented May 13, 2020

listitem only allows naming from "author". For the accessible name the contents are ignored. Only aria-label and aria-labelledby work.

I strongly advise against adding aria-label just to be able to query by accessible name. Test the implications with assistive technology first.

Related discussion in w3c/aria: w3c/aria#1117

@Raynos
Copy link
Author

Raynos commented May 13, 2020

I basically came here from https://stackoverflow.com/a/61669469/419970

I noticed that getByText does not work with a span but does work with getByRole so I thought getByRole was a good replacement for getByText

I guess getByRole is good for getting buttons that are kind of static but not for dynamic text in <p> or <span> or <li>

@Raynos
Copy link
Author

Raynos commented May 13, 2020

I also came from testing-library/dom-testing-library#201 (comment)

Where it says getByRole would help.

@eps1lon
Copy link
Owner

eps1lon commented May 13, 2020

I guess getByRole is good for getting buttons that are kind of static but not for dynamic text in

or or

  • ByRole is for querying elements with an accessible role with the option to filter by their name. Most elements have one but not listitem.

    I think we can close since it is working as intended.

    @eps1lon eps1lon closed this as completed May 13, 2020
    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

    No branches or pull requests

    2 participants