Skip to content

Commit

Permalink
fix(InputMenu/SelectMenu): look in items only with value-attribute
Browse files Browse the repository at this point in the history
Resolves #2464
  • Loading branch information
benjamincanac committed Nov 8, 2024
1 parent f943f88 commit 0ceafe1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/runtime/components/InputMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,17 @@ const ui = computed(() => inputMenu({
buttonGroup: orientation.value
}))
function displayValue(value: AcceptableValue): string {
const item = items.value.find(item => props.valueKey ? isEqual(get(item as Record<string, any>, props.valueKey as string), value) : isEqual(item, value))
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 => isEqual(get(item as Record<string, any>, props.valueKey as string), value))
return item && (typeof item === 'object' ? get(item, props.labelKey as string) : item)
}
function filterFunction(items: ArrayOrWrapped<AcceptableValue>, searchTerm: string): ArrayOrWrapped<AcceptableValue> {
function filterFunction(items: ArrayOrWrapped<T>, searchTerm: string): ArrayOrWrapped<T> {
if (props.filter === false) {
return items
}
Expand Down
8 changes: 6 additions & 2 deletions src/runtime/components/SelectMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,14 @@ const ui = computed(() => selectMenu({
function displayValue(value: T | T[]): string {
if (props.multiple && Array.isArray(value)) {
return value.map(v => displayValue(v)).join(', ')
return value.map(v => displayValue(v)).filter(Boolean).join(', ')
}
const item = items.value.find(item => props.valueKey ? isEqual(get(item as Record<string, any>, props.valueKey as string), value) : isEqual(item, value))
if (!props.valueKey) {
return value && (typeof value === 'object' ? get(value, props.labelKey as string) : value)
}
const item = items.value.find(item => isEqual(get(item as Record<string, any>, props.valueKey as string), value))
return item && (typeof item === 'object' ? get(item, props.labelKey as string) : item)
}
Expand Down

0 comments on commit 0ceafe1

Please sign in to comment.