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

feat(scrolltotop): add ScrollToTop component #1839

Merged
merged 1 commit into from
Dec 10, 2023
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
11 changes: 11 additions & 0 deletions src/components/scroll-to-top.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useEffect } from "react";
import { useLocation } from "react-router-dom";

export default function ScrollToTop() {
const { pathname } = useLocation();
useEffect(() => {
document.getElementsByTagName('main')?.[0]?.scrollTo(0, 0);
}, [pathname]);

return null;
}
2 changes: 2 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import ErrorBoundary from './components/ErrorBoundary';
import DashboardPage from './components/dashboard-page';
import ExtensionsEditorPage from './components/extensions-editor';
import GroupPage from './components/groups/GroupPage';
import ScrollToTop from './components/scroll-to-top';

import { ThemeSwitcherProvider } from 'react-css-theme-switcher';
import i18n from './i18n';
Expand All @@ -55,6 +56,7 @@ const Main = () => {
<Provider store={store}>
<ThemeSwitcherProvider themeMap={themes} defaultTheme={theme}>
<HashRouter>
<ScrollToTop />
<div className="main">
<NavBar />
<main className="content p-0 p-sm-3">
Expand Down
Loading