question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Passing `{ selected: true }` to `getByRole` of a radio / checkbox throws an error

See original GitHub issue

Describe 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 ARIA aria-selected or ARIA aria-checked.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
eps1loncommented, Jul 12, 2020

Why is a checked checkbox considered selected? As far as I know these are two different concepts.

0reactions
kentcdoddscommented, Jul 15, 2020

🎉 This issue has been resolved in version 7.21.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found