Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/runtime/components/InputMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,16 @@ function onUpdate(value: any) {
}

function onInputUpdate(value: string) {
if (!isAutocomplete.value) {
searchTerm.value = value
if (isAutocomplete.value) {
return
}

// While closed, reka resets the input to the label of the selected item, which isn't a search.
if (!isOpen.value && value && value === displayValue(props.modelValue as GetItemValue<T, VK, ExcludeItem>)) {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
return
}

searchTerm.value = value
}

function onBlur(event: FocusEvent) {
Expand All @@ -504,7 +511,12 @@ function onFocus(event: FocusEvent) {
emitFormFocus()
}

const isOpen = ref(false)
const isOpen = ref(props.open ?? props.defaultOpen ?? false)
watch(() => props.open, (value) => {
if (value !== undefined) {
isOpen.value = value
}
})
let timeoutId: ReturnType<typeof setTimeout> | undefined

onScopeDispose(() => clearTimeout(timeoutId))
Expand Down
21 changes: 21 additions & 0 deletions test/components/InputMenu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,27 @@ describe('InputMenu', () => {
expect(emissions).toBeTruthy()
expect(emissions![emissions!.length - 1]).toEqual(['Option 2'])
})

test('searchTerm ignores the label when parent updates modelValue', async () => {
const wrapper = mount(InputMenu, { props: { items: ['Option 1', 'Option 2'], modelValue: 'Option 1' } })
await flushPromises()

await wrapper.setProps({ modelValue: 'Option 2' })
await flushPromises()

expect(wrapper.emitted('update:searchTerm')?.flat() ?? []).not.toContain('Option 2')
})

test('searchTerm follows typing the selected label in a menu that starts open', async () => {
const wrapper = mount(InputMenu, { props: { items: ['Option 1', 'Option 2'], modelValue: 'Option 2', defaultOpen: true, portal: false } })
await flushPromises()

const input = wrapper.find('input')
await input.setValue('Option ')
await input.setValue('Option 2')

expect(wrapper.emitted('update:searchTerm')?.at(-1)).toEqual(['Option 2'])
})
})

describe('clear', () => {
Expand Down
Loading