Skip to content

Commit

Permalink
fix(SelectMenu): handle resetSearchTermOnBlur manually (#3082)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin Canac <[email protected]>
  • Loading branch information
rdjanuar and benjamincanac authored Jan 13, 2025
1 parent 1a54ab2 commit c902a40
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/runtime/components/SelectMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ import UInput from './Input.vue'
const props = withDefaults(defineProps<SelectMenuProps<T, I, V, M>>(), {
portal: true,
searchInput: true,
labelKey: 'label' as never
labelKey: 'label' as never,
resetSearchTermOnBlur: true
})
const emits = defineEmits<SelectMenuEmits<T, V, M>>()
const slots = defineSlots<SelectMenuSlots<T, M>>()
Expand Down Expand Up @@ -251,13 +252,27 @@ function onUpdate(value: any) {
}
function onUpdateOpen(value: boolean) {
let timeoutId
if (!value) {
const event = new FocusEvent('blur')
emits('blur', event)
emitFormBlur()
// Since we use `displayValue` prop inside ComboboxInput we should reset searchTerm manually
// https://reka-ui.com/docs/components/combobox#api-reference
if (props.resetSearchTermOnBlur) {
const STATE_ANIMATION_DELAY_MS = 100
timeoutId = setTimeout(() => {
searchTerm.value = ''
}, STATE_ANIMATION_DELAY_MS)
}
} else {
const event = new FocusEvent('focus')
emits('focus', event)
clearTimeout(timeoutId)
}
}
</script>
Expand Down

0 comments on commit c902a40

Please sign in to comment.