feat: selectOption works with role=radiogroup widgets - #5702
Merged
Conversation
A radio group is a "pick one of these" control, so the natural way to
write it is `I.selectOption('Density', 'Comfortable')`. Until now that
failed with "Element is not a <select> element", because selectOption
understood only `role=combobox` and `role=listbox` before falling back
to the native `<select>` path.
`role=radiogroup` is now a third rung of the fuzzy ladder in all three
helpers, and a third branch of proceedSelect: the descendant `role=radio`
whose accessible name matches the option is clicked. Radix Toggle Group in
single mode renders the same shape, so it is covered too.
The option name is matched exactly first and only then by substring —
Playwright's `name` option defaults to case-insensitive substring, which
would let 'Compact' be answered by a sibling named 'Compact mode'. An
unknown option raises ElementNotFound rather than timing out on a click,
and an array of two or more options is refused, since a radio group holds
a single value and clicking each in turn would silently keep the last.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TcwzSXPnfaig8nBZD2Vxfi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Makes
I.selectOption('Density', 'Comfortable')work onrole=radiogroupwidgets — the shape both Radix and Base UI render for a radio group, and the shape Radix Toggle Group takes in single mode.Until now
selectOptionunderstood two ARIA shapes,comboboxandlistbox, and anything else fell through to the native<select>path, which failed withlocator.selectOption: Error: Element is not a <select> element.What changed
role=radiogroupbecomes a third rung of the fuzzy locator ladder and a third branch ofproceedSelect, in Playwright, WebDriver and Puppeteer alike. The branch clicks the descendantrole=radiowhose accessible name matches the option, mirroring the existinglistboxbranch down to thedebugSectionoutput.Two details worth calling out:
getByRolenameoption defaults to a case-insensitive substring, so'Compact'would otherwise be answered by a sibling named'Compact mode'. The fixtures put'Compact mode'ahead of'Compact'in DOM order so the test is a real guard rather than a coincidence.ElementNotFoundrather than timing out on a click.Tests
test/helper/webapi.js,#selectOption - radiogroups, run by all three helpers. Three fixtures undertest/data/app/view/form/radiogroup/:plain.php— hand-writtendiv[role=radiogroup]withbutton[role=radio], plus a native<select>on the same page as a regression guardradix.php— RadixRadioGroupandToggleGroupin single modebaseui.php— Base UIRadioGroup, which also renders thearia-hiddenmirror inputsAssertions read
aria-checkedoff every radio in the group, so a step that passes without changing anything fails. Coverage: select by label, switch the selection, a group named byaria-labelledby, a strict CSS locator on the group, an unknown option, an array of two options, and a native<select>untouched.The Radix and Base UI fixtures pull the real libraries from esm.sh through an importmap, following the convention set by #5701 — so these three tests need network at run time, as the combobox ones already do.
Local results
test:unit,lint, and the full#selectOptionset green on Playwright, Puppeteer and WebDriver. NoisHelperguards were needed: every case passes on all three helpers.Part of the batch from the shadcn/Radix/Base UI component survey (§5 P7).
🤖 Generated with Claude Code
https://claude.ai/code/session_01TcwzSXPnfaig8nBZD2Vxfi