From f34c459c81e677e16d2aea6166c76d7fb3f70ffe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=C3=AFss?= Date: Wed, 29 Jan 2025 11:20:12 +0100 Subject: [PATCH] Fixes combobox selecting active option on blur --- .../src/components/combobox/combobox.ts | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/packages/@headlessui-vue/src/components/combobox/combobox.ts b/packages/@headlessui-vue/src/components/combobox/combobox.ts index 27b2a1c1d2..a4ce141de0 100644 --- a/packages/@headlessui-vue/src/components/combobox/combobox.ts +++ b/packages/@headlessui-vue/src/components/combobox/combobox.ts @@ -1225,23 +1225,15 @@ export let ComboboxInput = defineComponent({ if (api.comboboxState.value !== ComboboxStates.Open) return event.preventDefault() - if (api.mode.value === ValueMode.Single) { - // We want to clear the value when the user presses escape if and only if the current - // value is not set (aka, they didn't select anything yet, or they cleared the input which - // caused the value to be set to `null`). If the current value is set, then we want to - // fallback to that value when we press escape (this part is handled in the watcher that - // syncs the value with the input field again). - if (api.nullable.value && api.value.value === null) { - clear() - } - - // We do have a value, so let's select the active option, unless we were just going through - // the form and we opened it due to the focus event. - else if (api.activationTrigger.value !== ActivationTrigger.Focus) { - api.selectActiveOption() - } + // We want to clear the value when the user presses escape if and only if the current + // value is not set (aka, they didn't select anything yet, or they cleared the input which + // caused the value to be set to `null`). If the current value is set, then we want to + // fallback to that value when we press escape (this part is handled in the watcher that + // syncs the value with the input field again). + if (api.nullable.value && api.value.value === null) { + clear() } - + return api.closeCombobox() }