Skip to content

Commit c902a40

Browse files
rdjanuarbenjamincanac
andauthoredJan 13, 2025··
fix(SelectMenu): handle resetSearchTermOnBlur manually (#3082)
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
1 parent 1a54ab2 commit c902a40

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed
 

‎src/runtime/components/SelectMenu.vue

+16-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ import UInput from './Input.vue'
151151
const props = withDefaults(defineProps<SelectMenuProps<T, I, V, M>>(), {
152152
portal: true,
153153
searchInput: true,
154-
labelKey: 'label' as never
154+
labelKey: 'label' as never,
155+
resetSearchTermOnBlur: true
155156
})
156157
const emits = defineEmits<SelectMenuEmits<T, V, M>>()
157158
const slots = defineSlots<SelectMenuSlots<T, M>>()
@@ -251,13 +252,27 @@ function onUpdate(value: any) {
251252
}
252253
253254
function onUpdateOpen(value: boolean) {
255+
let timeoutId
256+
254257
if (!value) {
255258
const event = new FocusEvent('blur')
259+
256260
emits('blur', event)
257261
emitFormBlur()
262+
263+
// Since we use `displayValue` prop inside ComboboxInput we should reset searchTerm manually
264+
// https://reka-ui.com/docs/components/combobox#api-reference
265+
if (props.resetSearchTermOnBlur) {
266+
const STATE_ANIMATION_DELAY_MS = 100
267+
268+
timeoutId = setTimeout(() => {
269+
searchTerm.value = ''
270+
}, STATE_ANIMATION_DELAY_MS)
271+
}
258272
} else {
259273
const event = new FocusEvent('focus')
260274
emits('focus', event)
275+
clearTimeout(timeoutId)
261276
}
262277
}
263278
</script>

0 commit comments

Comments
 (0)
Please sign in to comment.