From 2adc529a5bcfae61d15265606f8e1b64c3cf6edf Mon Sep 17 00:00:00 2001 From: arabcoders Date: Fri, 22 Aug 2025 17:21:39 +0300 Subject: [PATCH] reset dropdown position when writing --- ui/app/components/InputAutocomplete.vue | 11 ++++++++++- ui/app/components/TextareaAutocomplete.vue | 11 +++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ui/app/components/InputAutocomplete.vue b/ui/app/components/InputAutocomplete.vue index 5d020777..2588cb50 100644 --- a/ui/app/components/InputAutocomplete.vue +++ b/ui/app/components/InputAutocomplete.vue @@ -88,7 +88,16 @@ const setDropdownItemRef = (el: Element | ComponentPublicInstance | null, idx: n dropdownItemRefs.value[idx] = el instanceof HTMLElement ? el : null } -watch(filteredOptions, () => dropdownItemRefs.value = Array(filteredOptions.value.length).fill(null)) +watch(filteredOptions, () => { + highlightedIndex.value = filteredOptions.value.length ? 0 : -1 + dropdownItemRefs.value = Array(filteredOptions.value.length).fill(null) + nextTick(() => { + const dropdown = document.querySelector('.dropdown-content') + if (dropdown) { + dropdown.scrollTop = 0 + } + }) +}) const handleKeydown = (e: KeyboardEvent) => { if (!filteredOptions.value.length) { diff --git a/ui/app/components/TextareaAutocomplete.vue b/ui/app/components/TextareaAutocomplete.vue index 93e68c03..ca0d7535 100644 --- a/ui/app/components/TextareaAutocomplete.vue +++ b/ui/app/components/TextareaAutocomplete.vue @@ -82,6 +82,17 @@ const onInput = () => { highlightedIndex.value = (showList.value && filteredOptions.value.length && lastWord.length > 0) ? 0 : -1 } +// Reset scroll position when filtered options change +watch(filteredOptions, () => { + highlightedIndex.value = filteredOptions.value.length > 0 && showList.value ? 0 : -1 + nextTick(() => { + const dropdown = document.querySelector('.dropdown-content') + if (dropdown) { + dropdown.scrollTop = 0 + } + }) +}) + const hideList = () => setTimeout(() => { showList.value = false; highlightedIndex.value = -1 }, 100) const onKeydown = (e: KeyboardEvent) => {