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

Shouldn't ByRole query find an element with display: none if I'm using hidden: true? #1333

Closed
felipecesr opened this issue Aug 13, 2024 · 1 comment

Comments

@felipecesr
Copy link

felipecesr commented Aug 13, 2024

I want to get an element with display: none style using the bellow query:

// Component
 <button style={{ display: 'none' }}>Button</button>

// Testing
screen.getByRole('button', { name: /button/i, hidden: true })

getByRole can't find the element. But it works if I use getByText like that:

screen.getByText(/button/i)

Is this the expected behavior? And why?

@felipecesr felipecesr changed the title Shouldn't ByRole query find an element with display: none if I'm using hidden: true? Shouldn't ByRole query find an element with display: none if I'm using hidden: true? Aug 13, 2024
@MatanBobi
Copy link
Member

Hi @felipecesr, thanks for opening this.
As you can see in the output of the test, hidden attributes have no accessible name:

Here are the available roles:

  button:

  Name "":
  <button
    style="display: none;"
  />

This is following the spec, the problem is browsers sometimes don't follow the spec and that's why you can see an accessible name in Chrome for example.
I'm closing this as works by design since we're spec compliant here.

@MatanBobi MatanBobi closed this as not planned Won't fix, can't repro, duplicate, stale Aug 14, 2024
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