Browse Source

fix: scroll to top when clicking current nav item

imwald
codytseng 10 months ago
parent
commit
23f6032808
  1. 4
      src/PageManager.tsx

4
src/PageManager.tsx

@ -196,11 +196,15 @@ export function PageManager({ maxStackSize = 5 }: { maxStackSize?: number }) { @@ -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()
}

Loading…
Cancel
Save