@@ -106,6 +106,48 @@ export const Fieldset = memo(
106106 return name_props ?? `radio-name-${ id } ` ;
107107 } ) ( ) ;
108108
109+ const renderOption = ( params : {
110+ option : FieldsetProps . Radio [ "options" ] [ number ] ;
111+ i : number | undefined ;
112+ } ) => {
113+ const { option, i } = params ;
114+ const { label, hintText, nativeInputProps, ...rest } = option ;
115+
116+ const isRoot = i === undefined ;
117+
118+ const inputId = getInputId ( i ?? 0 ) ;
119+
120+ return (
121+ < div
122+ className = { cx (
123+ fr . cx (
124+ `fr-${ type } -group` ,
125+ isRichRadio && "fr-radio-rich" ,
126+ small && `fr-${ type } -group--sm`
127+ ) ,
128+ isRoot ? className : undefined ,
129+ classes . inputGroup
130+ ) }
131+ key = { i }
132+ >
133+ < input type = { type } id = { inputId } name = { radioName } { ...nativeInputProps } />
134+ < label className = { fr . cx ( "fr-label" ) } htmlFor = { inputId } >
135+ { label }
136+ { hintText !== undefined && (
137+ < span className = { fr . cx ( "fr-hint-text" ) } > { hintText } </ span >
138+ ) }
139+ </ label >
140+ { "illustration" in rest && (
141+ < div className = { fr . cx ( "fr-radio-rich__img" ) } > { rest . illustration } </ div >
142+ ) }
143+ </ div >
144+ ) ;
145+ } ;
146+
147+ if ( legend === undefined && stateRelatedMessage === undefined && options . length === 1 ) {
148+ return renderOption ( { option : options [ 0 ] , i : undefined } ) ;
149+ }
150+
109151 return (
110152 < fieldset
111153 id = { id }
@@ -150,37 +192,7 @@ export const Fieldset = memo(
150192 </ legend >
151193 ) }
152194 < div className = { cx ( fr . cx ( "fr-fieldset__content" ) , classes . content ) } >
153- { options . map ( ( { label, hintText, nativeInputProps, ...rest } , i ) => (
154- < div
155- className = { cx (
156- fr . cx (
157- `fr-${ type } -group` ,
158- isRichRadio && "fr-radio-rich" ,
159- small && `fr-${ type } -group--sm`
160- ) ,
161- classes . inputGroup
162- ) }
163- key = { i }
164- >
165- < input
166- type = { type }
167- id = { getInputId ( i ) }
168- name = { radioName }
169- { ...nativeInputProps }
170- />
171- < label className = { fr . cx ( "fr-label" ) } htmlFor = { getInputId ( i ) } >
172- { label }
173- { hintText !== undefined && (
174- < span className = { fr . cx ( "fr-hint-text" ) } > { hintText } </ span >
175- ) }
176- </ label >
177- { "illustration" in rest && (
178- < div className = { fr . cx ( "fr-radio-rich__img" ) } >
179- { rest . illustration }
180- </ div >
181- ) }
182- </ div >
183- ) ) }
195+ { options . map ( ( option , i ) => renderOption ( { option, i } ) ) }
184196 </ div >
185197 < div
186198 className = { fr . cx ( "fr-messages-group" ) }
0 commit comments