Repository navigation
[radio] Add generic Value typing to Radio - #4033
Conversation
commit: |
Bundle size report
Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
3afd10e to
ef3ac54
Compare
Greptile OverviewGreptile SummaryThis PR adds a generic The main functional change is that Confidence Score: 3/5
Important Files Changed
|
Additional Comments (1)
Prompt To Fix With AIThis 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. |
86ce8c7 to
852347a
Compare
852347a to
69d31da
Compare
| */ | ||
| export const RadioGroup = React.forwardRef(function RadioGroup( | ||
| componentProps: RadioGroup.Props, | ||
| export const RadioGroup = React.forwardRef(function RadioGroup<Value>( |
There was a problem hiding this comment.
Should the value extend string? as in the Toggle component?
There was a problem hiding this comment.
Radio was originally unknown (then any) so it wasn't limited to strings. It supports numbers or objects already, so anything else is breaking
Same type updates as #3173