Skip to content

Commit

Permalink
feat(scrolltotop): add ScrollToTop component
Browse files Browse the repository at this point in the history
  • Loading branch information
TimBroddin committed Nov 24, 2023
1 parent 9af093c commit e0ba3d8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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

0 comments on commit e0ba3d8

Please sign in to comment.