@@ -348,6 +348,24 @@ export default defineComponent({
348
348
349
349
const [trigger, container] = usePopper (popper .value )
350
350
351
+ const by = computed (() => {
352
+ if (! props .by ) return undefined
353
+
354
+ if (typeof props .by === ' function' ) {
355
+ return props .by
356
+ }
357
+
358
+ const key = props .by
359
+ const hasDot = key .indexOf (' .' )
360
+ if (hasDot > 0 ) {
361
+ return (a : any , z : any ) => {
362
+ return accessor (a , key ) === accessor (z , key )
363
+ }
364
+ }
365
+
366
+ return key
367
+ })
368
+
351
369
const { size : sizeButtonGroup, rounded } = useInjectButtonGroup ({ ui , props })
352
370
const { emitFormBlur, emitFormChange, inputId, color, size : sizeFormGroup, name } = useFormGroup (props , config )
353
371
@@ -366,8 +384,8 @@ export default defineComponent({
366
384
367
385
const selected = computed (() => {
368
386
function compareValues(value1 : any , value2 : any ) {
369
- if (props . by && typeof value1 === ' object' && typeof value2 === ' object' ) {
370
- return isEqual (value1 [props . by ], value2 [props . by ])
387
+ if (by . value && typeof by . value !== ' function ' && typeof value1 === ' object' && typeof value2 === ' object' ) {
388
+ return isEqual (value1 [by . value ], value2 [by . value ])
371
389
}
372
390
return isEqual (value1 , value2 )
373
391
}
@@ -399,16 +417,12 @@ export default defineComponent({
399
417
})
400
418
401
419
const label = computed (() => {
402
- if (! selected .value ) return null
403
-
404
- if (props .valueAttribute ) {
405
- return accessor (selected .value as Record <string , any >, props .optionAttribute )
406
- }
420
+ if (! props .modelValue ) return null
407
421
408
422
if (Array .isArray (props .modelValue ) && props .modelValue .length ) {
409
423
return ` ${props .modelValue .length } selected `
410
424
} else if ([' string' , ' number' ].includes (typeof props .modelValue )) {
411
- return props .modelValue
425
+ return props .valueAttribute ? accessor ( selected . value , props . optionAttribute ) : props . modelValue
412
426
}
413
427
414
428
return accessor (props .modelValue as Record <string , any >, props .optionAttribute )
@@ -612,7 +626,9 @@ export default defineComponent({
612
626
// eslint-disable-next-line vue/no-dupe-keys
613
627
query ,
614
628
onUpdate ,
615
- onQueryChange
629
+ onQueryChange ,
630
+ // eslint-disable-next-line vue/no-dupe-keys
631
+ by
616
632
}
617
633
}
618
634
})
0 commit comments