Skip to content

[@mantine/core] Radio, Chip: Fix readOnly prop not preventing value changes - #9282

Merged
rtivital merged 2 commits into
mantinedev:masterfrom
aniruddhapw:fix/radio-chip-readonly
Oct 17, 2026
Merged

rtivital merged 2 commits into
mantinedev:masterfrom
aniruddhapw:fix/radio-chip-readonly

Conversation

@aniruddhapw

Copy link
Copy Markdown
Contributor

Bug

Radio and Chip with readOnly can still be changed by clicking. The prop goes to the native <input>, but browsers ignore readonly on radio and checkbox inputs. So clicking checks the input and calls onChange, in both controlled and uncontrolled mode. Checkbox already handles this (#8960), and Switch is being fixed in #9280.

Fix

Same approach as Checkbox:

  • Radio: skip onChange and the Radio.Group context update when readOnly; preventDefault() on click when uncontrolled.
  • Chip: skip the uncontrolled state update and the Chip.Group context update when readOnly.
  • Added a "Read only" section to the Radio and Chip docs pages.

Testing

  • 7 new tests in Radio.test.tsx and Chip.test.tsx cover controlled, uncontrolled and inside a group. 6 fail on master and pass with the fix. The 7th checks that a controlled radio stays in sync with outside changes.
  • Radio and Chip suites: 269 passed. oxlint and format:write:files are clean.

🤖 Generated with Claude Code

@rtivital rtivital added the Verified Reviewed and verified PR label Oct 13, 2026
@rtivital

Copy link
Copy Markdown
Member

🤖 Beep boop, Claude (Fable 5.1) speaking! Here are changes I've made in this PR:

  • Forwarded readOnly to the native input in Radio and Chip: destructuring it out of props had removed the readonly attribute from the input. Added an attribute assertion to the controlled readOnly tests.
  • Shortened the new "Read only" docs text on the Radio and Chip pages.

Verified in the browser: readOnly Radio and Chip (controlled, uncontrolled, inside Radio.Group and Chip.Group) do not change on click, Space or arrow keys and do not call onChange; programmatic checked updates still render; a user onClick on Radio still fires.

@rtivital
rtivital merged commit c062766 into mantinedev:master Oct 17, 2026
1 check passed
@rtivital

Copy link
Copy Markdown
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Verified Reviewed and verified PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants