Skip to content

feat: selectOption works with role=radiogroup widgets - #5702

Merged
DavertMik merged 1 commit into
4.xfrom
feat/selectoption-radiogroup
Sep 8, 2026
Merged

feat: selectOption works with role=radiogroup widgets#5702
DavertMik merged 1 commit into
4.xfrom
feat/selectoption-radiogroup

Conversation

@DavertMik

Copy link
Copy Markdown
Contributor

Makes I.selectOption('Density', 'Comfortable') work on role=radiogroup widgets — the shape both Radix and Base UI render for a radio group, and the shape Radix Toggle Group takes in single mode.

Until now selectOption understood two ARIA shapes, combobox and listbox, and anything else fell through to the native <select> path, which failed with locator.selectOption: Error: Element is not a <select> element.

What changed

role=radiogroup becomes a third rung of the fuzzy locator ladder and a third branch of proceedSelect, in Playwright, WebDriver and Puppeteer alike. The branch clicks the descendant role=radio whose accessible name matches the option, mirroring the existing listbox branch down to the debugSection output.

Two details worth calling out:

  • Exact name first, substring second. Playwright's getByRole name option 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.
  • An array of options is refused. A radio group holds one value; clicking each entry in turn would silently leave only the last one selected, so two or more options raise an error instead. An option that matches nothing raises ElementNotFound rather than timing out on a click.

Tests

test/helper/webapi.js, #selectOption - radiogroups, run by all three helpers. Three fixtures under test/data/app/view/form/radiogroup/:

  • plain.php — hand-written div[role=radiogroup] with button[role=radio], plus a native <select> on the same page as a regression guard
  • radix.php — Radix RadioGroup and ToggleGroup in single mode
  • baseui.php — Base UI RadioGroup, which also renders the aria-hidden mirror inputs

Assertions read aria-checked off every radio in the group, so a step that passes without changing anything fails. Coverage: select by label, switch the selection, a group named by aria-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 #selectOption set green on Playwright, Puppeteer and WebDriver. No isHelper guards 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

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
@DavertMik
DavertMik merged commit 6a98cae into 4.x Sep 8, 2026
15 of 16 checks passed
@DavertMik
DavertMik deleted the feat/selectoption-radiogroup branch September 8, 2026 23:22
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

Successfully merging this pull request may close these issues.

1 participant