Skip to content

[radio] Rely on individual radio hidden inputs - #3826

Merged
atomiks merged 1 commit into
mui:masterfrom
atomiks:refactor/radio-group-input
Jan 27, 2026
Merged

atomiks merged 1 commit into
mui:masterfrom
atomiks:refactor/radio-group-input

Conversation

@atomiks

@atomiks atomiks commented Jan 22, 2026 •

Copy link
Copy Markdown
Contributor

This removes the <RadioGroup>'s internal hidden input to instead rely on the individual radio buttons' inputs, aligning with native behavior. This also makes native validation bubbles position better by default, and uses the native radio validation message instead of <input type="text">: "Please select one of these options" instead of "Please fill in this field"

The group's inputRef is forwarded to the controlRef input for backward compatibility.

⚠️ Test expectations for the hidden input change here, but considering this was an implementation detail for testing, I think it's acceptable to change

@atomiks atomiks added the component: radio group Changes related to the radio group component. label Jan 22, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jan 22, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@3826
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@3826
    

commit: 0797778

@mui-bot

mui-bot commented Jan 22, 2026 •

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 🔺+301B(+0.07%) 🔺+147B(+0.11%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Jan 22, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 0797778
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6979392c606ce2000858baad
😎 Deploy Preview https://deploy-preview-3826--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@atomiks
atomiks force-pushed the refactor/radio-group-input branch 2 times, most recently from 7597717 to 8bc8861 Compare January 22, 2026 12:21
@atomiks
atomiks marked this pull request as ready for review January 22, 2026 12:25
@greptile-apps

greptile-apps Bot commented Jan 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR removes the RadioGroup's centralized hidden input and instead relies on each individual radio button's hidden input, aligning with native browser behavior.

Key changes:

  • Removed the group-level hidden input that was rendered inside RadioGroup
  • Each Radio.Root now has its own hidden input with the group's name attribute
  • The group's inputRef prop is synchronized to always point to the currently checked radio's input via a useIsoLayoutEffect hook
  • Native form validation bubbles now position correctly by default since they point to the actual radio inputs

Implementation details:

  • The ref synchronization in RadioRoot.tsx:87-107 properly handles both ref objects and ref callbacks (including cleanup functions for React 19+)
  • The validation.inputRef from the group context is merged into each radio's input, but only the checked radio's input is exposed via the group's inputRef prop
  • Tests were updated to reflect the new implementation, with comprehensive coverage of inputRef synchronization scenarios

This is a well-executed refactoring that improves alignment with native behavior while maintaining backward compatibility through the inputRef forwarding mechanism.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are well-tested with comprehensive test coverage for the new inputRef synchronization behavior. The implementation follows existing patterns in the codebase (ref merging is consistent with other components like Switch, Checkbox, etc.). The refactoring improves alignment with native browser behavior while maintaining backward compatibility. All modified tests pass with updated expectations that correctly reflect the new implementation.
  • No files require special attention

Important Files Changed

Filename Overview
packages/react/src/radio-group/RadioGroup.tsx Removed the group's hidden input and now forwards inputRef to context. Clean refactoring with proper aria-labelledby fallback logic.
packages/react/src/radio-group/RadioGroupContext.ts Added inputRef field to context interface and default value. Simple, safe addition.
packages/react/src/radio/root/RadioRoot.tsx Added ref synchronization logic to keep group's inputRef aligned with checked radio. Properly handles both ref objects and ref callbacks with cleanup.
packages/react/src/radio-group/RadioGroup.test.tsx Updated tests to reflect new implementation where each radio has its own input. Added comprehensive tests for inputRef synchronization.

@atomiks
atomiks force-pushed the refactor/radio-group-input branch 9 times, most recently from 5341519 to d522b68 Compare January 27, 2026 22:13
@atomiks
atomiks force-pushed the refactor/radio-group-input branch from d522b68 to 0797778 Compare January 27, 2026 22:16
@atomiks
atomiks merged commit 7db989f into mui:master Jan 27, 2026
@atomiks
atomiks deleted the refactor/radio-group-input branch January 27, 2026 22:23
atomiks added a commit to atomiks/base-ui that referenced this pull request Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: radio group Changes related to the radio group component.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants