Skip to content

Commit

Permalink
Fixes combobox selecting active option on blur
Browse files Browse the repository at this point in the history
  • Loading branch information
LadyAiss committed Jan 29, 2025
1 parent b6f355d commit f34c459
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions packages/@headlessui-vue/src/components/combobox/combobox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down

0 comments on commit f34c459

Please sign in to comment.