From e76fc7b04b590d2fb25d88c952e30b1cb57213cb Mon Sep 17 00:00:00 2001 From: jer3m01 Date: Sun, 25 Feb 2024 23:58:24 +0100 Subject: [PATCH] fix: toc --- .../docs/src/components/table-of-contents.tsx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/apps/docs/src/components/table-of-contents.tsx b/apps/docs/src/components/table-of-contents.tsx index 25aecb9d..b3426769 100644 --- a/apps/docs/src/components/table-of-contents.tsx +++ b/apps/docs/src/components/table-of-contents.tsx @@ -131,6 +131,24 @@ export function TableOfContents() { const currentSection = useCurrentSection(toc); + createEffect( + on( + () => currentSection(), + (currentSection) => { + if (isServer) return; + + const element = document.querySelector( + `a[data-toc-slug="${currentSection}"]`, + ); + + element?.scrollIntoView({ + behavior: "smooth", + block: "nearest", + }); + }, + ), + ); + return (