mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 12:14:41 +01:00
fix(InputMenu/SelectMenu): improve display value without valueKey
Resolves #4528
This commit is contained in:
@@ -233,11 +233,7 @@ const ui = computed(() => tv({ extend: tv(theme), ...(appConfig.ui?.inputMenu ||
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
function displayValue(value: T): string {
|
function displayValue(value: T): string {
|
||||||
if (!props.valueKey) {
|
const item = items.value.find(item => compare(typeof item === 'object' && props.valueKey ? get(item as Record<string, any>, props.valueKey as string) : item, value))
|
||||||
return value && (typeof value === 'object' ? get(value, props.labelKey as string) : value)
|
|
||||||
}
|
|
||||||
|
|
||||||
const item = items.value.find(item => compare(typeof item === 'object' ? get(item as Record<string, any>, props.valueKey as string) : item, value))
|
|
||||||
return item && (typeof item === 'object' ? get(item, props.labelKey as string) : item)
|
return item && (typeof item === 'object' ? get(item, props.labelKey as string) : item)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -439,7 +435,7 @@ defineExpose({
|
|||||||
<TagsInputItem v-for="(item, index) in tags" :key="index" :value="item" :class="ui.tagsItem({ class: [props.ui?.tagsItem, isInputItem(item) && item.ui?.tagsItem] })">
|
<TagsInputItem v-for="(item, index) in tags" :key="index" :value="item" :class="ui.tagsItem({ class: [props.ui?.tagsItem, isInputItem(item) && item.ui?.tagsItem] })">
|
||||||
<TagsInputItemText :class="ui.tagsItemText({ class: [props.ui?.tagsItemText, isInputItem(item) && item.ui?.tagsItemText] })">
|
<TagsInputItemText :class="ui.tagsItemText({ class: [props.ui?.tagsItemText, isInputItem(item) && item.ui?.tagsItemText] })">
|
||||||
<slot name="tags-item-text" :item="(item as NestedItem<T>)" :index="index">
|
<slot name="tags-item-text" :item="(item as NestedItem<T>)" :index="index">
|
||||||
{{ displayValue(item as T) }}
|
{{ displayValue(item as T) ?? item }}
|
||||||
</slot>
|
</slot>
|
||||||
</TagsInputItemText>
|
</TagsInputItemText>
|
||||||
|
|
||||||
|
|||||||
@@ -234,11 +234,7 @@ function displayValue(value: GetItemValue<T, VK> | GetItemValue<T, VK>[]): strin
|
|||||||
return values?.length ? values.join(', ') : undefined
|
return values?.length ? values.join(', ') : undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!props.valueKey) {
|
const item = items.value.find(item => compare(typeof item === 'object' && props.valueKey ? get(item as Record<string, any>, props.valueKey as string) : item, value))
|
||||||
return value && (typeof value === 'object' ? get(value, props.labelKey as string) : value)
|
|
||||||
}
|
|
||||||
|
|
||||||
const item = items.value.find(item => compare(typeof item === 'object' ? get(item as Record<string, any>, props.valueKey as string) : item, value))
|
|
||||||
return item && (typeof item === 'object' ? get(item, props.labelKey as string) : item)
|
return item && (typeof item === 'object' ? get(item, props.labelKey as string) : item)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user