Passing `{ selected: true }` to `getByRole` of a radio / checkbox throws an error
See original GitHub issueDescribe the feature you’d like:
Currently trying to find checked radio / checkbox throws an error "aria-selected" is not supported on role "radio".
I’d expect it to work for natively selected elements.
Suggested implementation:
Just try to find by checked first.
Describe alternatives you’ve considered:
Currently to get those, we need to filter
a getAllBy*
query:
const selected = getAllByLabelText('preference').filter(control => control.checked);
Teachability, Documentation, Adoption, Migration Strategy:
The WAI-ARIA spec separates aria-checked
from aria-selected
so maybe we can introduce this change too.
Or just update the docs to link to both.
Suggested tab example after implementing the change:
you can get the “Native”-tab by calling
getByRole('tab', { selected: true })
. To learn more about the selected state and which elements can have this state see ARIAaria-selected
or ARIAaria-checked
.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
How do I trigger a change event on radio buttons in react ...
It's correct to fire a change event, but you must pass a second parameter with the event data. This example works: import React...
Read more >user-event v13 - Testing Library
Pointer events options. Trying to click an element with pointer-events being set to "none" (i.e. unclickable) will throw an error.
Read more >Basic Recipes for React Testing Library - TK
One specific "feature" the getBy has is to throw an error if it doesn't find the ... select, multi-select, radio button, checkbox, etc):....
Read more >Radio button not passing desired values to my controller
Hi, I need some assistance on radio button which is not passing value true or false to my controller. It's always false not...
Read more >ARIA: radio role - Accessibility - MDN Web Docs
The radio role is one of a group of checkable radio buttons, ... a radio button is checked, the radio element has aria-checked...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Why is a checked checkbox considered selected? As far as I know these are two different concepts.
🎉 This issue has been resolved in version 7.21.0 🎉
The release is available on:
npm package (@latest dist-tag)
Your semantic-release bot 📦🚀