diff --git a/src/runtime/components/InputMenu.vue b/src/runtime/components/InputMenu.vue index bd4eb559..0c1bc4b2 100644 --- a/src/runtime/components/InputMenu.vue +++ b/src/runtime/components/InputMenu.vue @@ -233,11 +233,7 @@ const ui = computed(() => tv({ extend: tv(theme), ...(appConfig.ui?.inputMenu || })) function displayValue(value: T): string { - if (!props.valueKey) { - 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, props.valueKey as string) : item, value)) + const item = items.value.find(item => compare(typeof item === 'object' && props.valueKey ? get(item as Record, props.valueKey as string) : item, value)) return item && (typeof item === 'object' ? get(item, props.labelKey as string) : item) } @@ -439,7 +435,7 @@ defineExpose({ - {{ displayValue(item as T) }} + {{ displayValue(item as T) ?? item }} diff --git a/src/runtime/components/SelectMenu.vue b/src/runtime/components/SelectMenu.vue index 61614f99..983a2196 100644 --- a/src/runtime/components/SelectMenu.vue +++ b/src/runtime/components/SelectMenu.vue @@ -234,11 +234,7 @@ function displayValue(value: GetItemValue | GetItemValue[]): strin return values?.length ? values.join(', ') : undefined } - if (!props.valueKey) { - 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, props.valueKey as string) : item, value)) + const item = items.value.find(item => compare(typeof item === 'object' && props.valueKey ? get(item as Record, props.valueKey as string) : item, value)) return item && (typeof item === 'object' ? get(item, props.labelKey as string) : item) }