Skip to content

Commit

Permalink
fix: toc
Browse files Browse the repository at this point in the history
  • Loading branch information
jer3m01 committed Feb 25, 2024
1 parent faad31f commit e76fc7b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions apps/docs/src/components/table-of-contents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div class="hidden xl:sticky xl:top-[4.5rem] xl:block xl:h-[calc(100vh-4.5rem)] xl:flex-none xl:overflow-y-auto xl:py-4 xl:pr-6">
<nav aria-labelledby="on-this-page-title" class="w-56">
Expand All @@ -147,6 +165,7 @@ export function TableOfContents() {
<li>
<h3>
<a
data-toc-slug={section.slug}
href={`${path.pathname}#${section.slug}`}
class={clsx(
"block w-full font-sans transition font-normal rounded px-3 py-2 hover:bg-sky-50 dark:hover:bg-sky-900/20",
Expand Down

0 comments on commit e76fc7b

Please sign in to comment.