Skip to content

Commit

Permalink
fix(CommandPalette): activate first option after async search (#981)
Browse files Browse the repository at this point in the history
  • Loading branch information
flozdra authored Nov 16, 2023
1 parent e1e5fa9 commit a975939
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/runtime/components/navigation/CommandPalette.vue
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export default defineComponent({
onMounted(() => {
if (props.autoselect) {
activateFirstOption()
activateNextOption()
}
})
Expand Down Expand Up @@ -282,16 +282,14 @@ export default defineComponent({
}))
isLoading.value = false
activateFirstOption()
}, props.debounce)
watch(query, () => {
debouncedSearch()
// Select first item on search changes
setTimeout(() => {
// https://github.com/tailwindlabs/headlessui/blob/6fa6074cd5d3a96f78a2d965392aa44101f5eede/packages/%40headlessui-vue/src/components/combobox/combobox.ts#L804
comboboxInput.value?.$el.dispatchEvent(new KeyboardEvent('keydown', { key: 'PageUp' }))
}, 0)
activateFirstOption()
})
const iconName = computed(() => {
Expand All @@ -315,9 +313,15 @@ export default defineComponent({
// Methods
function activateFirstOption () {
// hack combobox by using keyboard event
// https://github.com/tailwindlabs/headlessui/blob/6fa6074cd5d3a96f78a2d965392aa44101f5eede/packages/%40headlessui-vue/src/components/combobox/combobox.ts#L769
setTimeout(() => {
// https://github.com/tailwindlabs/headlessui/blob/6fa6074cd5d3a96f78a2d965392aa44101f5eede/packages/%40headlessui-vue/src/components/combobox/combobox.ts#L804
comboboxInput.value?.$el.dispatchEvent(new KeyboardEvent('keydown', { key: 'PageUp' }))
}, 0)
}
function activateNextOption () {
setTimeout(() => {
// https://github.com/tailwindlabs/headlessui/blob/6fa6074cd5d3a96f78a2d965392aa44101f5eede/packages/%40headlessui-vue/src/components/combobox/combobox.ts#L769
comboboxInput.value?.$el.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowDown' }))
}, 0)
}
Expand Down

1 comment on commit a975939

@vercel
Copy link

@vercel vercel bot commented on a975939 Nov 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ui – ./

ui-git-dev-nuxt-js.vercel.app
ui-nuxt-js.vercel.app
ui.nuxt.com

Please sign in to comment.