@@ -10,36 +10,32 @@ import { useOptionalFieldContext, useOptionalFieldControlProps } from '../field/
1010import { radioInputMarker } from './radio.markers.stylex' ;
1111import { firstLine , indicatorSizes , sizes , styles } from './radio.styles' ;
1212
13- export interface RadioGroupProps < T extends string = string >
13+ export interface RadioGroupProps < Value = string >
1414 extends Omit < React . ComponentPropsWithoutRef < 'div' > , 'defaultValue' | 'className' | 'style' > , MosaicStyleProps {
15- value ?: T ;
16- defaultValue ?: T ;
17- onValueChange ?: ( value : T ) => void ;
15+ value ?: Value ;
16+ defaultValue ?: Value ;
17+ onValueChange ?: ( value : Value ) => void ;
1818 name ?: string ;
1919 disabled ?: boolean ;
2020}
2121
2222interface RadioGroupContextValue {
2323 name : string ;
2424 submits : boolean ;
25- value : string | undefined ;
26- setValue : ( value : string ) => void ;
25+ value : unknown ;
26+ setValue : ( value : unknown ) => void ;
2727 disabled : boolean | undefined ;
2828}
2929
3030const RadioGroupContext = React . createContext < RadioGroupContextValue | null > ( null ) ;
3131
3232// eslint-disable-next-line typescript/consistent-type-assertions -- The ref wrapper drops the value type parameter; the group only hands back values its caller passed in.
33- const RadioGroup = React . forwardRef < HTMLDivElement , RadioGroupProps > ( function MosaicRadioGroup (
33+ const RadioGroup = React . forwardRef < HTMLDivElement , RadioGroupProps < unknown > > ( function MosaicRadioGroup (
3434 { value : valueProp , defaultValue, onValueChange, name : nameProp , disabled, xstyle, ...rest } ,
3535 ref ,
3636) {
3737 const generatedName = React . useId ( ) ;
38- const [ value , setValue ] = useControllableState < string | undefined > ( valueProp , defaultValue , next => {
39- if ( next !== undefined ) {
40- onValueChange ?.( next ) ;
41- }
42- } ) ;
38+ const [ value , setValue ] = useControllableState ( valueProp , defaultValue , onValueChange ) ;
4339 const context = React . useMemo < RadioGroupContextValue > (
4440 ( ) => ( { name : nameProp ?? generatedName , submits : nameProp !== undefined , value, setValue, disabled } ) ,
4541 [ nameProp , generatedName , value , setValue , disabled ] ,
@@ -55,16 +51,14 @@ const RadioGroup = React.forwardRef<HTMLDivElement, RadioGroupProps>(function Mo
5551 />
5652 </ RadioGroupContext . Provider >
5753 ) ;
58- } ) as < T extends string = string > (
59- props : RadioGroupProps < T > & { ref ?: React . Ref < HTMLDivElement > } ,
60- ) => React . ReactElement ;
54+ } ) as < Value = string > ( props : RadioGroupProps < Value > & { ref ?: React . Ref < HTMLDivElement > } ) => React . ReactElement ;
6155
6256export interface RadioItemProps
6357 extends
6458 Omit < React . ComponentPropsWithoutRef < 'input' > , 'type' | 'size' | 'value' | 'className' | 'style' > ,
6559 MosaicStyleProps {
6660 size ?: 'sm' | 'md' ;
67- value ?: string ;
61+ value ?: unknown ;
6862}
6963
7064const RadioItem = React . forwardRef < HTMLInputElement , RadioItemProps > ( function MosaicRadioItem (
@@ -94,7 +88,7 @@ const RadioItem = React.forwardRef<HTMLInputElement, RadioItemProps>(function Mo
9488 } ) ;
9589 const group = React . useContext ( RadioGroupContext ) ;
9690 const disabled = ( fieldProps ?. disabled ?? disabledProp ) || group ?. disabled ;
97- const checked = group && value !== undefined ? group . value === value : checkedProp ;
91+ const checked = group && value !== undefined ? Object . is ( group . value , value ) : checkedProp ;
9892
9993 return (
10094 < span
@@ -106,7 +100,7 @@ const RadioItem = React.forwardRef<HTMLInputElement, RadioItemProps>(function Mo
106100 < input
107101 ref = { ref }
108102 type = 'radio'
109- value = { value }
103+ value = { typeof value === 'string' ? value : undefined }
110104 name = { group ?. name ?? nameProp }
111105 form = { group ?. submits === false ? '' : undefined }
112106 checked = { checked }
0 commit comments