fix(Select/SelectMenu): prevent empty string display when multiple

Regression of 7df7ee336a
This commit is contained in:
Benjamin Canac
2025-05-28 17:33:59 +02:00
parent 5835eb5f0f
commit 483e473e3f
7 changed files with 19 additions and 10 deletions

View File

@@ -193,9 +193,10 @@ const groups = computed<SelectItem[][]>(() =>
// eslint-disable-next-line vue/no-dupe-keys
const items = computed(() => groups.value.flatMap(group => group) as T[])
function displayValue(value?: GetItemValue<T, VK> | GetItemValue<T, VK>[]): string {
function displayValue(value: GetItemValue<T, VK> | GetItemValue<T, VK>[]): string | undefined {
if (props.multiple && Array.isArray(value)) {
return value.map(v => displayValue(v)).filter(Boolean).join(', ')
const values = value.map(v => displayValue(v)).filter(Boolean)
return values?.length ? values.join(', ') : undefined
}
const item = items.value.find(item => compare(typeof item === 'object' ? get(item as Record<string, any>, props.valueKey as string) : item, value))

View File

@@ -225,9 +225,10 @@ const ui = computed(() => tv({ extend: tv(theme), ...(appConfig.ui?.selectMenu |
buttonGroup: orientation.value
}))
function displayValue(value: GetItemValue<T, VK> | GetItemValue<T, VK>[]): string {
function displayValue(value: GetItemValue<T, VK> | GetItemValue<T, VK>[]): string | undefined {
if (props.multiple && Array.isArray(value)) {
return value.map(v => displayValue(v)).filter(Boolean).join(', ')
const values = value.map(v => displayValue(v)).filter(Boolean)
return values?.length ? values.join(', ') : undefined
}
if (!props.valueKey) {