@@ -78,18 +78,20 @@ export const Fieldset = memo(
7878
7979 assert < Equals < keyof typeof rest , never > > ( ) ;
8080
81- const { getInputId, legendId, errorDescId, successDescId } = ( function useClosure ( ) {
82- const id = `${ type } ${ name_props === undefined ? "" : `-${ name_props } ` } -${ useId ( ) } ` ;
81+ const { getInputId, legendId, errorDescId, successDescId, messagesWrapperId } =
82+ ( function useClosure ( ) {
83+ const id = `${ type } ${ name_props === undefined ? "" : `-${ name_props } ` } -${ useId ( ) } ` ;
8384
84- const getInputId = ( i : number ) => `${ id } -${ i } ` ;
85+ const getInputId = ( i : number ) => `${ id } -${ i } ` ;
8586
86- const legendId = `${ id } -legend` ;
87+ const legendId = `${ id } -legend` ;
8788
88- const errorDescId = `${ id } -desc-error` ;
89- const successDescId = `${ id } -desc-valid` ;
89+ const errorDescId = `${ id } -desc-error` ;
90+ const successDescId = `${ id } -desc-valid` ;
91+ const messagesWrapperId = `${ id } -messages` ;
9092
91- return { getInputId, legendId, errorDescId, successDescId } ;
92- } ) ( ) ;
93+ return { getInputId, legendId, errorDescId, successDescId, messagesWrapperId } ;
94+ } ) ( ) ;
9395
9496 const radioName = ( function useClosure ( ) {
9597 const id = useId ( ) ;
@@ -119,19 +121,7 @@ export const Fieldset = memo(
119121 ) }
120122 disabled = { disabled }
121123 style = { style }
122- aria-labelledby = { cx (
123- legendId ,
124- ( ( ) => {
125- switch ( state ) {
126- case "default" :
127- return undefined ;
128- case "error" :
129- return errorDescId ;
130- case "success" :
131- return successDescId ;
132- }
133- } ) ( )
134- ) }
124+ aria-labelledby = { cx ( legend !== undefined && legendId , messagesWrapperId ) }
135125 role = { state === "default" ? undefined : "group" }
136126 { ...rest }
137127 ref = { ref }
@@ -171,37 +161,37 @@ export const Fieldset = memo(
171161 </ div >
172162 ) ) }
173163 </ div >
174- { state !== "default" && (
175- < div
176- className = "fr-messages-group"
177- id = "radio-rich-error-messages"
178- aria-live = "assertive"
179- >
180- < p
181- id = { ( ( ) => {
182- switch ( state ) {
183- case "error" :
184- return errorDescId ;
185- case "success" :
186- return successDescId ;
187- }
188- } ) ( ) }
189- className = { fr . cx (
190- ( ( ) => {
164+ < div
165+ className = { fr . cx ( "fr-messages-group" ) }
166+ id = { messagesWrapperId }
167+ aria-live = "assertive"
168+ >
169+ { stateRelatedMessage !== undefined && (
170+ < p
171+ id = { ( ( ) => {
191172 switch ( state ) {
192173 case "error" :
193- return "fr-error-text" ;
174+ return errorDescId ;
194175 case "success" :
195- return "fr-valid-text" ;
176+ return successDescId ;
196177 }
197- } ) ( ) ,
198- "fr-message"
199- ) }
200- >
201- { stateRelatedMessage ?? "" }
202- </ p >
203- </ div >
204- ) }
178+ } ) ( ) }
179+ className = { fr . cx (
180+ ( ( ) => {
181+ switch ( state ) {
182+ case "error" :
183+ return "fr-error-text" ;
184+ case "success" :
185+ return "fr-valid-text" ;
186+ }
187+ } ) ( ) ,
188+ "fr-message"
189+ ) }
190+ >
191+ { stateRelatedMessage }
192+ </ p >
193+ ) }
194+ </ div >
205195 </ fieldset >
206196 ) ;
207197 } )
0 commit comments