From 23f6032808ee70717c6a6288549bb940f3ae7cdf Mon Sep 17 00:00:00 2001 From: codytseng Date: Thu, 8 May 2025 09:25:10 +0800 Subject: [PATCH] fix: scroll to top when clicking current nav item --- src/PageManager.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/PageManager.tsx b/src/PageManager.tsx index b3f6484..853d477 100644 --- a/src/PageManager.tsx +++ b/src/PageManager.tsx @@ -196,11 +196,15 @@ export function PageManager({ maxStackSize = 5 }: { maxStackSize?: number }) { }, []) const navigatePrimaryPage = (page: TPrimaryPageName) => { + const needScrollToTop = page === currentPrimaryPage const exists = primaryPages.find((p) => p.name === page) if (!exists) { setPrimaryPages((prev) => [...prev, { name: page, element: PRIMARY_PAGE_MAP[page] }]) } setCurrentPrimaryPage(page) + if (needScrollToTop) { + PRIMARY_PAGE_REF_MAP[page].current?.scrollToTop() + } if (isSmallScreen) { clearSecondaryPages() }