From f61efc6bb75b651782ae3f158b12e7fd43b08809 Mon Sep 17 00:00:00 2001 From: Khalid Waleed Date: Tue, 8 Apr 2025 00:19:52 +0200 Subject: [PATCH] fix: setHash is not triggered unless scrolled after section a bit --- src/components/PageLinks.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/PageLinks.tsx b/src/components/PageLinks.tsx index a2669cf..ed19803 100644 --- a/src/components/PageLinks.tsx +++ b/src/components/PageLinks.tsx @@ -15,8 +15,10 @@ export function PageLinks({ items = [], className, ...props }: PageLinksProps) { useEffect(() => { const callback = () => { const x = [...items].reverse().find(({ id }) => { - const rect = document.getElementById(id)?.getBoundingClientRect(); - return rect && rect.top <= 0; + const contentSection = document.getElementById(id); + const rect = contentSection?.getBoundingClientRect(); + const scrollMarginTop = contentSection?.style?.scrollMarginTop ?? 0; + return rect && rect.top <= scrollMarginTop; }); if (x) setHash(x.id);