@@ -65,13 +65,11 @@ export const Select = memo(
65
65
66
66
const messagesGroupId = `${ selectId } -messages-group` ;
67
67
68
- const selectStateDescriptionId = useId ( ) ;
69
- const stateIsDefault = state === "default" ;
70
-
71
- const stateDescriptionId = getStateDescriptionId ( stateIsDefault , selectStateDescriptionId ) ;
72
- const nativeDescription = getSelectNativeDescription ( nativeSelectProps [ "aria-describedby" ] ) ;
68
+ const stateDescriptionId = ( function useClosure ( ) {
69
+ const id = useId ( ) ;
73
70
74
- const selectAriaDescribedBy = `${ stateDescriptionId } ${ nativeDescription } ` . trim ( ) ;
71
+ return state === "default" ? undefined : `select-${ id } -desc` ;
72
+ } ) ( ) ;
75
73
76
74
return (
77
75
< div
@@ -111,13 +109,13 @@ export const Select = memo(
111
109
{ ...nativeSelectProps }
112
110
className = { cx ( fr . cx ( "fr-select" ) , nativeSelectProps . className ) }
113
111
id = { selectId }
114
- aria-describedby = { selectAriaDescribedBy }
112
+ aria-describedby = { cx ( stateDescriptionId , nativeSelectProps [ "aria-describedby" ] ) }
115
113
disabled = { disabled }
116
114
>
117
115
{ children }
118
116
</ select >
119
117
< div id = { messagesGroupId } className = { fr . cx ( "fr-messages-group" ) } aria-live = "polite" >
120
- { ! stateIsDefault && (
118
+ { state !== "default" && (
121
119
< p
122
120
id = { stateDescriptionId }
123
121
className = { fr . cx (
@@ -143,16 +141,6 @@ export const Select = memo(
143
141
} )
144
142
) ;
145
143
146
- function getStateDescriptionId ( stateIsDefault : boolean , selectStateDescriptionId : string ) {
147
- return stateIsDefault ? "" : `select-${ selectStateDescriptionId } -desc` ;
148
- }
149
-
150
- function getSelectNativeDescription (
151
- nativeSelectPropsAriaDescribedBy : React . SelectHTMLAttributes < HTMLSelectElement > [ "aria-describedby" ]
152
- ) {
153
- return nativeSelectPropsAriaDescribedBy !== undefined ? nativeSelectPropsAriaDescribedBy : "" ;
154
- }
155
-
156
144
Select . displayName = symToStr ( { Select } ) ;
157
145
158
146
export default Select ;
0 commit comments