Skip to content

[radio] Add generic Value typing to Radio - #4033

Merged
atomiks merged 3 commits into
mui:masterfrom
atomiks:codex/radio-type-inference-3173
Feb 11, 2026
Merged

atomiks merged 3 commits into
mui:masterfrom
atomiks:codex/radio-type-inference-3173

Conversation

@atomiks

@atomiks atomiks commented Feb 10, 2026

Copy link
Copy Markdown
Contributor

Same type updates as #3173

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

pkg-pr-new Bot commented Feb 10, 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@4033
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@4033
    

commit: 72d00eb

@mui-bot

mui-bot commented Feb 10, 2026 •

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react ▼-122B(-0.03%) ▼-3B(0.00%)

Details of bundle changes


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

@netlify

netlify Bot commented Feb 10, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 72d00eb
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/698c6a339c773900087770fb
😎 Deploy Preview https://deploy-preview-4033--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 codex/radio-type-inference-3173 branch from 3afd10e to ef3ac54 Compare February 10, 2026 02:49
@atomiks
atomiks marked this pull request as ready for review February 10, 2026 02:51
@greptile-apps

greptile-apps Bot commented Feb 10, 2026

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

This PR adds a generic Value type parameter to RadioGroup and Radio.Root so that value, defaultValue, and onValueChange can be strongly typed and inferred, with new type-level spec files asserting inference and explicit generic behavior.

The main functional change is that RadioGroupContext is now generic and RadioRoot consumes it as useRadioGroupContext<Value>() so checkedValue/setCheckedValue are typed consistently through the group → radio pipeline.

Confidence Score: 3/5

  • This PR is close to mergeable but has a couple of type-safety/runtime-default issues in the new generic RadioGroup context that should be corrected first.
  • Generic typing for RadioGroup/RadioRoot is largely consistent and covered by new type assertions, but RadioGroupContext’s default value and the generic useRadioGroupContext<Value>() cast are unsound and can lead to incorrect behavior or unsafe typing when used without (or mismatched with) a provider.
  • packages/react/src/radio-group/RadioGroupContext.ts

Important Files Changed

Filename Overview
packages/react/src/radio-group/RadioGroup.spec.tsx Adds type-level JSX assertions for RadioGroup generic Value inference and null handling.
packages/react/src/radio-group/RadioGroup.tsx Makes RadioGroup generic over Value and threads Value through context and callbacks; introduces a generic forwardRef cast that may drop ref typing.
packages/react/src/radio-group/RadioGroupContext.ts Makes RadioGroupContext generic and changes checkedValue from unknown to Value; createContext default uses any and a string sentinel for checkedValue.
packages/react/src/radio/root/RadioRoot.spec.tsx Adds type-only JSX assertions verifying Radio.Root generic Value accepts inferred values and rejects mismatched explicit generic values.
packages/react/src/radio/root/RadioRoot.tsx Makes RadioRoot generic over Value and threads it through useRadioGroupContext<Value>() and RadioRootProps<Value>; preserves generic call signature via type assertion.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@greptile-apps

greptile-apps Bot commented Feb 10, 2026

Copy link
Copy Markdown
Contributor
Additional Comments (1)

packages/react/src/radio-group/RadioGroupContext.ts
Invalid default context value

RadioGroupContext now requires checkedValue: Value, but the createContext fallback uses checkedValue: '' (RadioGroupContext.ts:29-35). If a Radio.Root is rendered outside a RadioGroup (or a consumer calls useRadioGroupContext<Value>() without a provider), checkedValue will be a string regardless of Value, and RadioRoot.tsx compares checkedValue === value (RadioRoot.tsx:79), which can silently produce incorrect checked state for non-string values. The default should stay type-safe for the “no provider” case (e.g., checkedValue should be undefined-like and the interface should reflect that) instead of a string sentinel.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/react/src/radio-group/RadioGroupContext.ts
Line: 29:35

Comment:
**Invalid default context value**

`RadioGroupContext` now requires `checkedValue: Value`, but the `createContext` fallback uses `checkedValue: ''` (`RadioGroupContext.ts:29-35`). If a `Radio.Root` is rendered outside a `RadioGroup` (or a consumer calls `useRadioGroupContext<Value>()` without a provider), `checkedValue` will be a string regardless of `Value`, and `RadioRoot.tsx` compares `checkedValue === value` (`RadioRoot.tsx:79`), which can silently produce incorrect `checked` state for non-string values. The default should stay type-safe for the “no provider” case (e.g., `checkedValue` should be `undefined`-like and the interface should reflect that) instead of a string sentinel.

How can I resolve this? If you propose a fix, please make it concise.

@atomiks
atomiks force-pushed the codex/radio-type-inference-3173 branch 3 times, most recently from 86ce8c7 to 852347a Compare February 10, 2026 03:11
@atomiks
atomiks force-pushed the codex/radio-type-inference-3173 branch from 852347a to 69d31da Compare February 10, 2026 03:15
*/
export const RadioGroup = React.forwardRef(function RadioGroup(
componentProps: RadioGroup.Props,
export const RadioGroup = React.forwardRef(function RadioGroup<Value>(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the value extend string? as in the Toggle component?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Radio was originally unknown (then any) so it wasn't limited to strings. It supports numbers or objects already, so anything else is breaking

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough 👌

@atomiks
atomiks merged commit e937bcc into mui:master Feb 11, 2026
7 checks passed
@atomiks atomiks mentioned this pull request Feb 19, 2026
1 task done
@atomiks
atomiks deleted the codex/radio-type-inference-3173 branch August 11, 2026 03:02
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. typescript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants