Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 5 additions & 4 deletions src/runtime/components/SelectMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,11 @@ onMounted(() => {
onScopeDispose(() => clearTimeout(autofocusTimeoutId))

function onUpdate(value: any) {
// Selecting the current item emits it again, which still resets the search.
if (props.resetSearchTermOnSelect) {
searchTerm.value = ''
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}

if (toRaw(props.modelValue) === value) {
return
}
Expand All @@ -454,10 +459,6 @@ function onUpdate(value: any) {
emits('change', event)
emitFormChange()
emitFormInput()

if (props.resetSearchTermOnSelect) {
searchTerm.value = ''
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

const isOpen = ref(false)
Expand Down
9 changes: 9 additions & 0 deletions test/components/SelectMenu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,15 @@ describe('SelectMenu', () => {
input.vm.$emit('update:open', false)
expect(wrapper.emitted()).toMatchObject({ blur: [[{ type: 'blur' }]] })
})

test('resets the search term when selecting the current item', async () => {
const wrapper = mount(SelectMenu, { props: { items: ['Option 1', 'Option 2'], modelValue: 'Option 1', searchTerm: 'Option', resetSearchTermOnBlur: false } })
const input = wrapper.findComponent({ name: 'ComboboxRoot' })
await input.setValue('Option 1')

expect(wrapper.emitted('update:searchTerm')).toEqual([['']])
expect(wrapper.emitted('change')).toBeUndefined()
})
})

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