mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-02-02 13:17:57 +01:00
fix(CommandPalette): activate first option after async search (#981)
This commit is contained in:
@@ -189,7 +189,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (props.autoselect) {
|
if (props.autoselect) {
|
||||||
activateFirstOption()
|
activateNextOption()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -282,16 +282,14 @@ export default defineComponent({
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
isLoading.value = false
|
isLoading.value = false
|
||||||
|
|
||||||
|
activateFirstOption()
|
||||||
}, props.debounce)
|
}, props.debounce)
|
||||||
|
|
||||||
watch(query, () => {
|
watch(query, () => {
|
||||||
debouncedSearch()
|
debouncedSearch()
|
||||||
|
|
||||||
// Select first item on search changes
|
activateFirstOption()
|
||||||
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)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const iconName = computed(() => {
|
const iconName = computed(() => {
|
||||||
@@ -315,9 +313,15 @@ export default defineComponent({
|
|||||||
// Methods
|
// Methods
|
||||||
|
|
||||||
function activateFirstOption () {
|
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(() => {
|
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' }))
|
comboboxInput.value?.$el.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowDown' }))
|
||||||
}, 0)
|
}, 0)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user