@@ -42,7 +42,7 @@ type DefaultOptionValue = string | number | readonly string[] | undefined;
4242/**
4343 * @see <https://react-dsfr-components.etalab.studio/?path=/docs/components-select>
4444 * */
45- export const Select = < T extends GenericOption < DefaultOptionValue > [ ] > (
45+ const SelectComponent = < T extends GenericOption < DefaultOptionValue > [ ] > (
4646 props : SelectProps < T > ,
4747 ref : React . LegacyRef < HTMLDivElement >
4848) => {
@@ -61,19 +61,22 @@ export const Select = <T extends GenericOption<DefaultOptionValue>[]>(
6161 } = props ;
6262
6363 assert < Equals < keyof typeof rest , never > > ( ) ;
64- const elementId = nativeSelectProps ?. id || useId ( ) ;
65- const selectId = `select-${ elementId } ` ;
66- const stateDescriptionId = `select-${ elementId } -desc` ;
67- const displayedOptions = placeholder
68- ? [
69- {
70- label : placeholder ,
71- value : "" ,
72- disabled : true
73- } ,
74- ...options
75- ]
76- : options ;
64+ const elementId = useId ( ) ;
65+ const selectId = nativeSelectProps ?. id || `select-${ elementId } ` ;
66+ const stateDescriptionId = nativeSelectProps ?. id
67+ ? `${ nativeSelectProps ?. id } -desc`
68+ : `select-${ elementId } -desc` ;
69+ const displayedOptions =
70+ placeholder !== undefined
71+ ? [
72+ {
73+ label : placeholder ,
74+ value : "" ,
75+ disabled : true
76+ } ,
77+ ...options
78+ ]
79+ : options ;
7780 return (
7881 < div
7982 className = { cx (
@@ -109,8 +112,10 @@ export const Select = <T extends GenericOption<DefaultOptionValue>[]>(
109112 aria-describedby = { stateDescriptionId }
110113 disabled = { disabled }
111114 >
112- { displayedOptions . map ( option => (
113- < option { ...option } > { option . label } </ option >
115+ { displayedOptions . map ( ( option , index ) => (
116+ < option { ...option } key = { `${ option . value } -${ index } ` } >
117+ { option . label }
118+ </ option >
114119 ) ) }
115120 </ select >
116121 { state !== "default" && (
@@ -135,13 +140,16 @@ export const Select = <T extends GenericOption<DefaultOptionValue>[]>(
135140 ) ;
136141} ;
137142
138- const ForwardedSelect = forwardRef ( Select ) as < T extends GenericOption < DefaultOptionValue > [ ] > (
143+ const ForwardedSelect = forwardRef ( SelectComponent ) as <
144+ T extends GenericOption < DefaultOptionValue > [ ]
145+ > (
139146 props : SelectProps < T > & { ref ?: ForwardedRef < HTMLDivElement > }
140- ) => ReturnType < typeof Select > ;
147+ ) => ReturnType < typeof SelectComponent > ;
141148
142- const MemoizedSelect = memo ( ForwardedSelect ) as typeof ForwardedSelect & {
149+ export const Select = memo ( ForwardedSelect ) as typeof ForwardedSelect & {
143150 displayName : string ;
144151} ;
145- MemoizedSelect . displayName = symToStr ( { Select } ) ;
146152
147- export default MemoizedSelect ;
153+ Select . displayName = symToStr ( { Select } ) ;
154+
155+ export default Select ;
0 commit comments