mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-20 06:51:46 +01:00
fix(InputMenu/SelectMenu): allow access nested object in option-attribute (#2465)
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
@@ -63,7 +63,7 @@
|
||||
/>
|
||||
<span v-else-if="option.chip" :class="uiMenu.option.chip.base" :style="{ background: `#${option.chip}` }" />
|
||||
|
||||
<span class="truncate">{{ ['string', 'number'].includes(typeof option) ? option : option[optionAttribute] }}</span>
|
||||
<span class="truncate">{{ ['string', 'number'].includes(typeof option) ? option : accessor(option, optionAttribute) }}</span>
|
||||
</slot>
|
||||
</div>
|
||||
|
||||
@@ -310,9 +310,9 @@ export default defineComponent({
|
||||
|
||||
if (props.valueAttribute) {
|
||||
const option = options.value.find(option => option[props.valueAttribute] === props.modelValue)
|
||||
return option ? option[props.optionAttribute] : null
|
||||
return option ? accessor(option, props.optionAttribute) : null
|
||||
} else {
|
||||
return ['string', 'number'].includes(typeof props.modelValue) ? props.modelValue : props.modelValue[props.optionAttribute]
|
||||
return ['string', 'number'].includes(typeof props.modelValue) ? props.modelValue : accessor(props.modelValue as Record<string, any>, props.optionAttribute)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -442,6 +442,10 @@ export default defineComponent({
|
||||
emitFormChange()
|
||||
}
|
||||
|
||||
function accessor<T extends Record<string, any>>(obj: T, key: string) {
|
||||
return get(obj, key)
|
||||
}
|
||||
|
||||
function onQueryChange(event: any) {
|
||||
query.value = event.target.value
|
||||
}
|
||||
@@ -475,6 +479,7 @@ export default defineComponent({
|
||||
filteredOptions,
|
||||
// eslint-disable-next-line vue/no-dupe-keys
|
||||
query,
|
||||
accessor,
|
||||
onUpdate,
|
||||
onQueryChange
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user