Skip to content

Commit 1a93791

Browse files
committed
fix(InputMenu): take option-attribute into account to display label
1 parent b9fe74b commit 1a93791

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

docs/components/content/examples/InputMenuExampleObjectsValueAttribute.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ const people = [{
1313
name: 'Tom Cook'
1414
}]
1515
16-
const selected = ref(people[0].name)
16+
const selected = ref(people[0].id)
1717
</script>
1818

1919
<template>
2020
<UInputMenu
2121
v-model="selected"
2222
:options="people"
23-
value-attribute="name"
23+
value-attribute="id"
2424
option-attribute="name"
2525
/>
2626
</template>

src/runtime/components/forms/InputMenu.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
:class="inputClass"
2020
autocomplete="off"
2121
v-bind="attrs"
22-
:display-value="() => query ? query : ['string', 'number'].includes(typeof modelValue) ? modelValue : modelValue[optionAttribute]"
22+
:display-value="() => query ? query : label"
2323
@change="onChange"
2424
/>
2525

@@ -293,6 +293,15 @@ export default defineComponent({
293293
}
294294
})
295295
296+
const label = computed(() => {
297+
if (props.valueAttribute) {
298+
const option = props.options.find(option => option[props.valueAttribute] === props.modelValue)
299+
return option ? option[props.optionAttribute] : null
300+
} else {
301+
return ['string', 'number'].includes(typeof props.modelValue) ? props.modelValue : props.modelValue[props.optionAttribute]
302+
}
303+
})
304+
296305
const inputClass = computed(() => {
297306
const variant = ui.value.color?.[color.value as string]?.[props.variant as string] || ui.value.variant[props.variant]
298307
@@ -423,6 +432,7 @@ export default defineComponent({
423432
popper,
424433
trigger,
425434
container,
435+
label,
426436
isLeading,
427437
isTrailing,
428438
// eslint-disable-next-line vue/no-dupe-keys

0 commit comments

Comments
 (0)