Commit 8e2384e70d

8e2384e70d405d8886927884b1f5a7f925b5c23f

parent: ad36479526

Unsigned

TubaApollo <86665265+TubaApollo@users.noreply.github.com> · 2026-04-10 13:48 UTC

fix: sidebar arrow scrolling for all pages and search focus-trap scroll bug

- Extend arrow key scrolling to regular VitePress sidebar (not just homepage)
- Move SidebarCard inside nav for consistent spacing
- Fix focus-trap deactivation scrolling page to top after search navigation

Layout: unified · split

docs/.vitepress/theme/Layout.vue +12 −10
@@ -175,18 +175,20 @@ onMounted(() => {
175175
176176 // Arrow key scrolling + Escape close for desktop sidebar
177177 useEventListener(document, 'keydown', (e: KeyboardEvent) => {
178 if (!homeSidebarOpen.value || !sidebarRef.value) return
178 if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp' && e.key !== 'Escape') return
179
179180 if (e.key === 'Escape') {
180 homeSidebarOpen.value = false
181 if (homeSidebarOpen.value) homeSidebarOpen.value = false
181182 return
182183 }
183 if (e.key === 'ArrowDown') {
184 e.preventDefault()
185 sidebarRef.value.scrollBy({ top: 60, behavior: 'smooth' })
186 } else if (e.key === 'ArrowUp') {
187 e.preventDefault()
188 sidebarRef.value.scrollBy({ top: -60, behavior: 'smooth' })
189 }
184
185 const target = homeSidebarOpen.value
186 ? sidebarRef.value
187 : !isHome.value ? document.querySelector<HTMLElement>('.VPSidebar') : null
188 if (!target) return
189
190 e.preventDefault()
191 target.scrollBy({ top: e.key === 'ArrowDown' ? 60 : -60, behavior: 'smooth' })
190192 })
191193
192194 // Close home NavScreen on outside click
@@ -256,8 +258,8 @@ onUnmounted(() => {
256258 </div>
257259 <nav id="VPSidebarNav" class="home-sidebar-nav">
258260 <VPSidebarGroup :items="homeSidebarGroups" />
261 <SidebarCard />
259262 </nav>
260 <SidebarCard />
261263 </aside>
262264 </Transition>
263265 </template>
docs/.vitepress/theme/components/Search.vue +1
@@ -95,6 +95,7 @@ const { activate } = useFocusTrap(el, {
9595 allowOutsideClick: true,
9696 clickOutsideDeactivates: true,
9797 escapeDeactivates: true,
98 returnFocusOnDeactivate: false,
9899 initialFocus: () => {
99100 return searchInput.value
100101 }