Skip to content

Commit 4d4234d

Browse files
committed
fix(InputMenu/SelectMenu): improve display value without valueKey
Resolves #4528
1 parent 6f38d3e commit 4d4234d

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

‎src/runtime/components/InputMenu.vue

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,7 @@ const ui = computed(() => tv({ extend: tv(theme), ...(appConfig.ui?.inputMenu ||
233233
}))
234234
235235
function displayValue(value: T): string {
236-
if (!props.valueKey) {
237-
return value && (typeof value === 'object' ? get(value, props.labelKey as string) : value)
238-
}
239-
240-
const item = items.value.find(item => compare(typeof item === 'object' ? get(item as Record<string, any>, props.valueKey as string) : item, value))
236+
const item = items.value.find(item => compare(typeof item === 'object' && props.valueKey ? get(item as Record<string, any>, props.valueKey as string) : item, value))
241237
return item && (typeof item === 'object' ? get(item, props.labelKey as string) : item)
242238
}
243239
@@ -439,7 +435,7 @@ defineExpose({
439435
<TagsInputItem v-for="(item, index) in tags" :key="index" :value="item" :class="ui.tagsItem({ class: [props.ui?.tagsItem, isInputItem(item) && item.ui?.tagsItem] })">
440436
<TagsInputItemText :class="ui.tagsItemText({ class: [props.ui?.tagsItemText, isInputItem(item) && item.ui?.tagsItemText] })">
441437
<slot name="tags-item-text" :item="(item as NestedItem<T>)" :index="index">
442-
{{ displayValue(item as T) }}
438+
{{ displayValue(item as T) ?? item }}
443439
</slot>
444440
</TagsInputItemText>
445441

‎src/runtime/components/SelectMenu.vue

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,7 @@ function displayValue(value: GetItemValue<T, VK> | GetItemValue<T, VK>[]): strin
234234
return values?.length ? values.join(', ') : undefined
235235
}
236236
237-
if (!props.valueKey) {
238-
return value && (typeof value === 'object' ? get(value, props.labelKey as string) : value)
239-
}
240-
241-
const item = items.value.find(item => compare(typeof item === 'object' ? get(item as Record<string, any>, props.valueKey as string) : item, value))
237+
const item = items.value.find(item => compare(typeof item === 'object' && props.valueKey ? get(item as Record<string, any>, props.valueKey as string) : item, value))
242238
return item && (typeof item === 'object' ? get(item, props.labelKey as string) : item)
243239
}
244240

0 commit comments

Comments
 (0)