File tree Expand file tree Collapse file tree 5 files changed +49
-19
lines changed Expand file tree Collapse file tree 5 files changed +49
-19
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import {
21
21
getBoolean ,
22
22
getBooleanAsString ,
23
23
getHideProp ,
24
+ getOptionKey ,
24
25
getSearchInput ,
25
26
handleDataOutside ,
26
27
hasVoiceOver ,
@@ -201,9 +202,6 @@ export default function DBCustomSelect(props: DBCustomSelectProps) {
201
202
202
203
return false ;
203
204
} ,
204
- getOptionKey : ( option : CustomSelectOptionType ) => {
205
- return ( option . id ?? option . value ?? uuid ( ) ) . toString ( ) ;
206
- } ,
207
205
getTagRemoveLabel : ( index : number ) => {
208
206
if (
209
207
props . removeTagsTexts &&
@@ -776,9 +774,10 @@ export default function DBCustomSelect(props: DBCustomSelectProps) {
776
774
key = { useTarget ( {
777
775
vue : undefined ,
778
776
stencil : undefined ,
779
- default :
780
- 'native-select-option-' +
781
- state . getOptionKey ( option )
777
+ default : getOptionKey (
778
+ option ,
779
+ 'native-select-option-'
780
+ )
782
781
} ) }
783
782
disabled = { option . disabled }
784
783
value = { option . value } >
@@ -823,9 +822,10 @@ export default function DBCustomSelect(props: DBCustomSelectProps) {
823
822
key = { useTarget ( {
824
823
vue : undefined ,
825
824
stencil : undefined ,
826
- default :
827
- 'tag-' +
828
- state . getOptionKey ( option )
825
+ default : getOptionKey (
826
+ option ,
827
+ 'tag-'
828
+ )
829
829
} ) }
830
830
removeButton = { state . getTagRemoveLabel (
831
831
index
@@ -920,11 +920,10 @@ export default function DBCustomSelect(props: DBCustomSelectProps) {
920
920
key = { useTarget ( {
921
921
vue : undefined ,
922
922
stencil : undefined ,
923
- default :
924
- 'custom-select-list-item-' +
925
- state . getOptionKey (
926
- option
927
- )
923
+ default : getOptionKey (
924
+ option ,
925
+ 'custom-select-list-item-'
926
+ )
928
927
} ) }
929
928
type = {
930
929
props . multiple
Original file line number Diff line number Diff line change @@ -260,7 +260,6 @@ export type DBCustomSelectDefaultState = {
260
260
getNativeSelectValue : ( ) => string ;
261
261
getOptionLabel : ( option : CustomSelectOptionType ) => string ;
262
262
getOptionChecked : ( value ?: string ) => boolean ;
263
- getOptionKey : ( option : CustomSelectOptionType ) => string ;
264
263
getTagRemoveLabel : ( index : number ) => string ;
265
264
selectAllEnabled : boolean ;
266
265
searchEnabled : boolean ;
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import {
15
15
delay ,
16
16
getBoolean ,
17
17
getHideProp ,
18
+ getOptionKey ,
18
19
hasVoiceOver ,
19
20
stringPropVisible ,
20
21
uuid
@@ -228,28 +229,51 @@ export default function DBSelect(props: DBSelectProps) {
228
229
aria-describedby = { props . ariaDescribedBy ?? state . _descByIds } >
229
230
{ /* Empty option for floating label */ }
230
231
< option hidden > </ option >
231
- < Show when = { props . options } else = { props . children } >
232
+ < Show when = { props . options ?. length } else = { props . children } >
232
233
< For each = { props . options } >
233
234
{ ( option : DBSelectOptionType ) => (
234
235
< >
235
236
< Show
236
237
when = { option . options }
237
238
else = {
238
239
< option
240
+ key = { useTarget ( {
241
+ vue : undefined ,
242
+ stencil : undefined ,
243
+ default : getOptionKey (
244
+ option ,
245
+ 'select-option-'
246
+ )
247
+ } ) }
239
248
value = { option . value }
240
249
disabled = { option . disabled }
241
250
selected = { option . selected } >
242
251
{ state . getOptionLabel ( option ) }
243
252
</ option >
244
253
} >
245
254
< optgroup
246
- label = { state . getOptionLabel ( option ) } >
255
+ label = { state . getOptionLabel ( option ) }
256
+ key = { useTarget ( {
257
+ vue : undefined ,
258
+ stencil : undefined ,
259
+ default : getOptionKey (
260
+ option ,
261
+ 'select-optgroup-'
262
+ )
263
+ } ) } >
247
264
< For each = { option . options } >
248
265
{ (
249
266
optgroupOption : DBSelectOptionType
250
267
) => (
251
268
< option
252
- key = { optgroupOption . value . toString ( ) }
269
+ key = { useTarget ( {
270
+ vue : undefined ,
271
+ stencil : undefined ,
272
+ default : getOptionKey (
273
+ optgroupOption ,
274
+ 'select-optgroup-option-'
275
+ )
276
+ } ) }
253
277
value = { optgroupOption . value }
254
278
selected = {
255
279
optgroupOption . selected
Original file line number Diff line number Diff line change @@ -224,3 +224,11 @@ export const stringPropVisible = (
224
224
225
225
export const getSearchInput = ( element : HTMLElement ) : HTMLInputElement | null =>
226
226
element . querySelector < HTMLInputElement > ( `input[type="search"]` ) ;
227
+
228
+ export const getOptionKey = (
229
+ option : { id ?: string ; value ?: string | number | string [ ] | undefined } ,
230
+ prefix : string
231
+ ) => {
232
+ const key = option . id ?? option . value ?? uuid ( ) ;
233
+ return `${ prefix } ${ key } ` ;
234
+ } ;
Original file line number Diff line number Diff line change 430
430
"name" : " True" ,
431
431
"props" : {
432
432
"icon" : " x_placeholder" ,
433
- "content" : true
433
+ "content" : " true"
434
434
}
435
435
}
436
436
]
You can’t perform that action at this time.
0 commit comments