@@ -16,11 +16,11 @@ import { firstLine, indicatorSizes, layouts, sizes, styles } from './radio.style
1616/** `stack` gives each choice its own row. `grid` fits as many columns of cards as the width allows. */
1717export type RadioLayout = 'stack' | 'grid' ;
1818
19- export interface RadioGroupProps < T extends string = string >
19+ export interface RadioGroupProps < Value = string >
2020 extends Omit < React . ComponentPropsWithoutRef < 'div' > , 'defaultValue' | 'className' | 'style' > , MosaicStyleProps {
21- value ?: T ;
22- defaultValue ?: T ;
23- onValueChange ?: ( value : T ) => void ;
21+ value ?: Value ;
22+ defaultValue ?: Value ;
23+ onValueChange ?: ( value : Value ) => void ;
2424 name ?: string ;
2525 disabled ?: boolean ;
2626 /** @default 'stack' */
@@ -30,24 +30,20 @@ export interface RadioGroupProps<T extends string = string>
3030interface RadioGroupContextValue {
3131 name : string ;
3232 submits : boolean ;
33- value : string | undefined ;
34- setValue : ( value : string ) => void ;
33+ value : unknown ;
34+ setValue : ( value : unknown ) => void ;
3535 disabled : boolean | undefined ;
3636}
3737
3838const RadioGroupContext = React . createContext < RadioGroupContextValue | null > ( null ) ;
3939
4040// 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.
41- const RadioGroup = React . forwardRef < HTMLDivElement , RadioGroupProps > ( function MosaicRadioGroup (
41+ const RadioGroup = React . forwardRef < HTMLDivElement , RadioGroupProps < unknown > > ( function MosaicRadioGroup (
4242 { value : valueProp , defaultValue, onValueChange, name : nameProp , disabled, layout = 'stack' , xstyle, ...rest } ,
4343 ref ,
4444) {
4545 const generatedName = React . useId ( ) ;
46- const [ value , setValue ] = useControllableState < string | undefined > ( valueProp , defaultValue , next => {
47- if ( next !== undefined ) {
48- onValueChange ?.( next ) ;
49- }
50- } ) ;
46+ const [ value , setValue ] = useControllableState ( valueProp , defaultValue , onValueChange ) ;
5147 const context = React . useMemo < RadioGroupContextValue > (
5248 ( ) => ( { name : nameProp ?? generatedName , submits : nameProp !== undefined , value, setValue, disabled } ) ,
5349 [ nameProp , generatedName , value , setValue , disabled ] ,
@@ -67,16 +63,14 @@ const RadioGroup = React.forwardRef<HTMLDivElement, RadioGroupProps>(function Mo
6763 />
6864 </ RadioGroupContext . Provider >
6965 ) ;
70- } ) as < T extends string = string > (
71- props : RadioGroupProps < T > & { ref ?: React . Ref < HTMLDivElement > } ,
72- ) => React . ReactElement ;
66+ } ) as < Value = string > ( props : RadioGroupProps < Value > & { ref ?: React . Ref < HTMLDivElement > } ) => React . ReactElement ;
7367
7468export interface RadioItemProps
7569 extends
7670 Omit < React . ComponentPropsWithoutRef < 'input' > , 'type' | 'size' | 'value' | 'className' | 'style' > ,
7771 MosaicStyleProps {
7872 size ?: 'sm' | 'md' ;
79- value ?: string ;
73+ value ?: unknown ;
8074}
8175
8276const RadioItem = React . forwardRef < HTMLInputElement , RadioItemProps > ( function MosaicRadioItem (
@@ -106,7 +100,7 @@ const RadioItem = React.forwardRef<HTMLInputElement, RadioItemProps>(function Mo
106100 } ) ;
107101 const group = React . useContext ( RadioGroupContext ) ;
108102 const disabled = ( fieldProps ?. disabled ?? disabledProp ) || group ?. disabled ;
109- const checked = group && value !== undefined ? group . value === value : checkedProp ;
103+ const checked = group && value !== undefined ? Object . is ( group . value , value ) : checkedProp ;
110104
111105 return (
112106 < span
@@ -118,7 +112,7 @@ const RadioItem = React.forwardRef<HTMLInputElement, RadioItemProps>(function Mo
118112 < input
119113 ref = { ref }
120114 type = 'radio'
121- value = { value }
115+ value = { typeof value === 'string' ? value : undefined }
122116 name = { group ?. name ?? nameProp }
123117 form = { group ?. submits === false ? '' : undefined }
124118 checked = { checked }
@@ -200,7 +194,7 @@ const RadioSection = React.forwardRef<HTMLFieldSetElement, RadioSectionProps>(fu
200194
201195export interface RadioCardProps
202196 extends Omit < React . ComponentPropsWithoutRef < 'label' > , 'className' | 'style' > , MosaicStyleProps {
203- value : string ;
197+ value : unknown ;
204198 disabled ?: boolean ;
205199}
206200
@@ -219,7 +213,7 @@ const RadioCard = React.forwardRef<HTMLLabelElement, RadioCardProps>(function Mo
219213 ref ,
220214) {
221215 const group = React . useContext ( RadioGroupContext ) ;
222- const checked = group ?. value === value ;
216+ const checked = group !== null && Object . is ( group . value , value ) ;
223217
224218 return (
225219 < FieldProvider
0 commit comments