From 4529965b1a6bc09fbe59ca161dcfada309d72640 Mon Sep 17 00:00:00 2001 From: "Mr. Robot" Date: Mon, 23 Mar 2026 12:42:45 +0600 Subject: [PATCH 1/5] feat: highlight active item in package docs sidebar --- app/pages/package-docs/[...path].vue | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/app/pages/package-docs/[...path].vue b/app/pages/package-docs/[...path].vue index 37cf258219..0f49964611 100644 --- a/app/pages/package-docs/[...path].vue +++ b/app/pages/package-docs/[...path].vue @@ -138,6 +138,27 @@ const stickyStyle = computed(() => { '--combined-header-height': `${56 + (packageHeaderHeight.value || 44)}px`, } }) + +// Track active TOC item based on URL hash +const tocContainerRef = useTemplateRef('tocContainerRef') + +function updateActiveTocLink(hash: string) { + const container = tocContainerRef.value + if (!container) return + + container.querySelector('a.toc-active')?.classList.remove('toc-active') + + if (hash) { + const link = container.querySelector(`a[href="${CSS.escape(hash)}"]`) + link?.classList.add('toc-active') + } +} + +if (import.meta.client) { + watch(() => route.hash, hash => updateActiveTocLink(hash)) + watch(() => docsData.value?.toc, () => nextTick(() => updateActiveTocLink(route.hash))) + onMounted(() => updateActiveTocLink(route.hash)) +}