Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up scroll to top on page navigation #260

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions submit-web/src/components/ScrollToTop/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { useLocation } from "@tanstack/react-router";
import { useEffect } from "react";

const ScrollToTop = () => {
const { pathname, search } = useLocation();

useEffect(() => {
window.scrollTo(0, 0); // Scroll to the top of the page on route change
}, [pathname, search]); // Listen for changes in the pathname and search properties

return null;
};

export default ScrollToTop;
2 changes: 2 additions & 0 deletions submit-web/src/routes/__root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { QueryClient } from "@tanstack/react-query";
import { notify } from "@/components/Shared/Snackbar/snackbarStore";
import { AppConfig } from "@/utils/config";
import { When } from "react-if";
import ScrollToTop from "@/components/ScrollToTop";

type RouterContext = {
authentication: AuthContextProps;
Expand All @@ -34,6 +35,7 @@ function Layout() {
getResetKey={() => "reset"}
onCatch={(error) => notify.error(error.message)}
>
<ScrollToTop />
<EAOAppBar />
<DrawerProvider />
<Box minHeight={"calc(100vh - 88px)"}>
Expand Down