From 544ed48741080befab3bee40e6e6c10ce9855406 Mon Sep 17 00:00:00 2001 From: Heman Sran Date: Fri, 29 Dec 2023 13:06:56 -0700 Subject: [PATCH] - Fixed Sidebar scroll effect for last element in the settingLinks --- src/pages/parts/settings/SidebarPart.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/pages/parts/settings/SidebarPart.tsx b/src/pages/parts/settings/SidebarPart.tsx index 16c657d3..2b6e5c3f 100644 --- a/src/pages/parts/settings/SidebarPart.tsx +++ b/src/pages/parts/settings/SidebarPart.tsx @@ -82,17 +82,20 @@ export function SidebarPart() { const el = document.getElementById(link.id); if (!el) return { distance: Infinity, link: link.id }; const rect = el.getBoundingClientRect(); - const distanceTop = Math.abs(centerTarget - rect.top); const distanceBottom = Math.abs(centerTarget - rect.bottom); - const distance = Math.min(distanceBottom, distanceTop); return { distance, link: link.id }; }) .sort((a, b) => a.distance - b.distance); - // shortest distance to the part of the screen we want is the active link - setActiveLink(viewList[0]?.link ?? ""); + // Check if user has scrolled past the bottom of the page + if (window.innerHeight + window.scrollY >= document.body.offsetHeight) { + setActiveLink(settingLinks[settingLinks.length - 1].id); + } else { + // shortest distance to the part of the screen we want is the active link + setActiveLink(viewList[0]?.link ?? ""); + } } document.addEventListener("scroll", recheck); recheck();