fix: scroll to top when clicking current nav item
This commit is contained in:
@@ -196,11 +196,15 @@ export function PageManager({ maxStackSize = 5 }: { maxStackSize?: number }) {
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const navigatePrimaryPage = (page: TPrimaryPageName) => {
|
const navigatePrimaryPage = (page: TPrimaryPageName) => {
|
||||||
|
const needScrollToTop = page === currentPrimaryPage
|
||||||
const exists = primaryPages.find((p) => p.name === page)
|
const exists = primaryPages.find((p) => p.name === page)
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
setPrimaryPages((prev) => [...prev, { name: page, element: PRIMARY_PAGE_MAP[page] }])
|
setPrimaryPages((prev) => [...prev, { name: page, element: PRIMARY_PAGE_MAP[page] }])
|
||||||
}
|
}
|
||||||
setCurrentPrimaryPage(page)
|
setCurrentPrimaryPage(page)
|
||||||
|
if (needScrollToTop) {
|
||||||
|
PRIMARY_PAGE_REF_MAP[page].current?.scrollToTop()
|
||||||
|
}
|
||||||
if (isSmallScreen) {
|
if (isSmallScreen) {
|
||||||
clearSecondaryPages()
|
clearSecondaryPages()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user