Skip to content

Commit

Permalink
fix(InputMenu): take option-attribute into account to display label
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamincanac committed Jan 16, 2024
1 parent b9fe74b commit 1a93791
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ const people = [{
name: 'Tom Cook'
}]
const selected = ref(people[0].name)
const selected = ref(people[0].id)
</script>

<template>
<UInputMenu
v-model="selected"
:options="people"
value-attribute="name"
value-attribute="id"
option-attribute="name"
/>
</template>
12 changes: 11 additions & 1 deletion src/runtime/components/forms/InputMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
:class="inputClass"
autocomplete="off"
v-bind="attrs"
:display-value="() => query ? query : ['string', 'number'].includes(typeof modelValue) ? modelValue : modelValue[optionAttribute]"
:display-value="() => query ? query : label"
@change="onChange"
/>

Expand Down Expand Up @@ -293,6 +293,15 @@ export default defineComponent({
}
})
const label = computed(() => {
if (props.valueAttribute) {
const option = props.options.find(option => option[props.valueAttribute] === props.modelValue)
return option ? option[props.optionAttribute] : null
} else {
return ['string', 'number'].includes(typeof props.modelValue) ? props.modelValue : props.modelValue[props.optionAttribute]
}
})
const inputClass = computed(() => {
const variant = ui.value.color?.[color.value as string]?.[props.variant as string] || ui.value.variant[props.variant]
Expand Down Expand Up @@ -423,6 +432,7 @@ export default defineComponent({
popper,
trigger,
container,
label,
isLeading,
isTrailing,
// eslint-disable-next-line vue/no-dupe-keys
Expand Down

1 comment on commit 1a93791

@vercel
Copy link

@vercel vercel bot commented on 1a93791 Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ui – ./

ui-nuxt-js.vercel.app
ui-git-dev-nuxt-js.vercel.app
ui.nuxt.com

Please sign in to comment.