refactor sticky scroll handler

- because of making the root's child div styles as override: auto it won't be a ref for the sticky category logic
This commit is contained in:
2025-10-07 12:57:05 +03:00
parent d8b06c097b
commit da9d7f8eb3
4 changed files with 215 additions and 79 deletions

View File

@@ -27,11 +27,29 @@ export const ScrollToTop: React.FC = () => {
const { pathname } = useLocation();
useEffect(() => {
window.scrollTo({
top: 0,
left: 0,
behavior: "smooth",
}); // Scroll to the top when the location changes
// Use a more stable approach to find the scroll container
const findScrollContainer = () => {
const antApp = document.querySelector('.ant-app') as HTMLElement;
if (antApp && antApp.scrollHeight > antApp.clientHeight) {
return antApp;
}
const appContainer = document.querySelector('[class*="App"]') as HTMLElement;
if (appContainer && appContainer.scrollHeight > appContainer.clientHeight) {
return appContainer;
}
return document.documentElement;
};
const scrollContainer = findScrollContainer();
if (scrollContainer) {
scrollContainer.scrollTo({
top: 0,
left: 0,
behavior: "smooth",
}); // Scroll to the top when the location changes
}
}, [pathname]);
return null; // This component doesn't render anything