From 7530652b90bc56de677739640dfa801c887cc802 Mon Sep 17 00:00:00 2001 From: jer3m01 Date: Sun, 25 Feb 2024 23:38:25 +0100 Subject: [PATCH] fix: toc --- .../docs/src/components/table-of-contents.tsx | 75 ++++++++++--------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/apps/docs/src/components/table-of-contents.tsx b/apps/docs/src/components/table-of-contents.tsx index 56798f79..70acb791 100644 --- a/apps/docs/src/components/table-of-contents.tsx +++ b/apps/docs/src/components/table-of-contents.tsx @@ -132,6 +132,25 @@ 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 (