Skip to content

Commit f2045e6

Browse files
fix(ui): readme toc dropdown scroll to the selected item position (#1917)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent d87e85c commit f2045e6

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

app/components/ReadmeTocDropdown.vue

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,27 @@ function handleKeydown(event: KeyboardEvent) {
139139
break
140140
}
141141
}
142+
143+
const itemScrollIntoView = (index: number) => {
144+
const item = props.toc[index]
145+
if (!item) return
146+
const el = document.getElementById(`${listboxId}-${item.id}`)
147+
if (el) {
148+
el.scrollIntoView({ block: 'center' })
149+
}
150+
}
151+
152+
watch(
153+
isOpen,
154+
open => {
155+
if (open && highlightedIndex.value >= 0) {
156+
itemScrollIntoView(highlightedIndex.value)
157+
}
158+
},
159+
{
160+
flush: 'post',
161+
},
162+
)
142163
</script>
143164

144165
<template>

0 commit comments

Comments
 (0)