Skip to content

Commit

Permalink
fix: itemRefs
Browse files Browse the repository at this point in the history
Signed-off-by: Hristiyan <[email protected]>
  • Loading branch information
icoxxx committed Jan 30, 2025
1 parent 8786557 commit adefad7
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions front-end/src/renderer/components/ui/AppAutoComplete.vue
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,8 @@ function setValue(value: string) {
}
function scrollToItem(index: number) {
const correctId = filteredItems.value[index];
const correctIndex = itemRefs.value.findIndex(item => item.innerText.startsWith(correctId));
nextTick(() => {
itemRefs.value[correctIndex]?.scrollIntoView({
itemRefs.value[index]?.scrollIntoView({
block: 'nearest',
});
handleResize();
Expand Down Expand Up @@ -223,6 +221,12 @@ function focusNextElement() {
}
}
function setItemRef(el: HTMLElement | null, index: number) {
if (el) {
itemRefs.value[index] = el;
}
}
/* Hooks */
onMounted(() => {
setTimeout(() => {
Expand Down Expand Up @@ -271,7 +275,7 @@ watchEffect(() => {
selected: i === selectedIndex,
}"
@click="handleSelectItem($event, item)"
ref="itemRefs"
:ref="el => setItemRef(el as HTMLElement, i)"
>
{{ item }}
</div>
Expand Down

0 comments on commit adefad7

Please sign in to comment.