Skip to content

Commit

Permalink
Don’t drop initial character when searching in Combobox (#1223)
Browse files Browse the repository at this point in the history
* Don’t drop initial character when searching in Combobox

* Update changelog
  • Loading branch information
thecrypticace authored Mar 9, 2022
1 parent 07c3a61 commit 236482a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Ignore "outside click" on removed elements ([#1193](https://github.com/tailwindlabs/headlessui/pull/1193))
- Remove `focus()` from Listbox Option ([#1218](https://github.com/tailwindlabs/headlessui/pull/1218))
- Improve some internal code ([#1221](https://github.com/tailwindlabs/headlessui/pull/1221))
- Don’t drop initial character when searching in Combobox ([#1223](https://github.com/tailwindlabs/headlessui/pull/1223))

### Added

Expand Down
17 changes: 16 additions & 1 deletion packages/@headlessui-vue/src/components/combobox/combobox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,25 @@ export let Combobox = defineComponent({
api.closeCombobox()
})

watch([api.value, api.inputRef, api.comboboxState], () => api.syncInputValue(), {
watch([api.value, api.inputRef], () => api.syncInputValue(), {
immediate: true,
})

// Only sync the input value on close as typing into the input will trigger it to open
// causing a resync of the input value with the currently stored, stale value that is
// one character behind since the input's value has just been updated by the browser
watch(
api.comboboxState,
(state) => {
if (state === ComboboxStates.Closed) {
api.syncInputValue()
}
},
{
immediate: true,
}
)

// @ts-expect-error Types of property 'dataRef' are incompatible.
provide(ComboboxContext, api)
useOpenClosedProvider(
Expand Down

0 comments on commit 236482a

Please sign in to comment.