-
Notifications
You must be signed in to change notification settings - Fork 474
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 narrowing getByRole with type #1012
Comments
I gave something similar a try and I kinda like it: https://github.com/juanca/accessible-query It does not check Or if it's okay to include it in this library, we can also copy-paste similar looking code. |
Thanks for the detailed explainer. The type is very specifc to buttons (and not related to ARIA properties like But the use case itself is fairly specific so we don't intend to include it at this point. If this request becomes more popular, we'll reconsider. PS:
You want to use the property instead since querying by attribute would miss the default value for the |
I came here looking for something similar (a way to find the default button that is triggered when you press Return when in a text field, even if there are multiple submit buttons). But after reading this, @eps1lon your proposed solution falls short in three regards:
Yes, this matcher option would only be needed for buttons, but buttons are a very important part of the web, with much hidden complexity. I feel it would not be excessive to provide specific support for them. @kentcdodds thoughts? |
Can you be more clear on what it is you want to have changed? For example, give us an example of code that you would like to be able to write if this were done. |
Describe the feature you'd like:
I've got a component like this:
Currently in my tests I'm doing this:
As afaik that's the most efficient query I can use to get the "submit" button (without adding a test-id).
The issue is that it's dependent on the text of the button being
Submit
- what I really want is to dogetByRole('button', { type: 'submit' })
to select "a submit button".Likewise this would be useful for the reset button which is in the same camp.
The only drawback I can think of here is a little increase in amount of code :)
Suggested implementation:
I've not looked at the code, but I'd expect this should be doable by checking if the node being checked has a
type
attribute and if so compare its value to thetype
option if present.Describe alternatives you've considered:
name
option ofgetByRole
, but that'd suffer from the same issue as above.Teachability, Documentation, Adoption, Migration Strategy:
I imagine it'd be a matter of updating the current docs for the role queries to include this as a new option, with a similar format as the docs for the existing options such as
checked
,selected
, etc.I'm happy to help try and implement this :)
The text was updated successfully, but these errors were encountered: