Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Scroll to top after clicking a link

dominik-zeglenb1f5c1f2ae06
diff --git a/saleor/static/dashboard-next/components/ScrollToTop.tsx b/saleor/static/dashboard-next/components/ScrollToTop.tsx
new file mode 100644
index 0000000000..13ff1d8499
--- /dev/null
+++ b/saleor/static/dashboard-next/components/ScrollToTop.tsx
@@ -0,0 +1,16 @@
+import * as React from "react";
+import { RouteComponentProps, withRouter } from "react-router-dom";
+
+class ScrollToTop extends React.Component<RouteComponentProps<{}>> {
+ componentDidUpdate(prevProps) {
+ if (this.props.location !== prevProps.location) {
+ window.scrollTo(0, 0);
+ }
+ }
+
+ render() {
+ return this.props.children;
+ }
+}
+
+export default withRouter(ScrollToTop);
diff --git a/saleor/static/dashboard-next/index.tsx b/saleor/static/dashboard-next/index.tsx
index 3c375a73ac..d67cbd98e4 100644
--- a/saleor/static/dashboard-next/index.tsx
+++ b/saleor/static/dashboard-next/index.tsx
@@ -22,6 +22,7 @@ import "./i18n";
import PageSection from "./pages";
import ProductSection from "./products";
import theme from "./theme";
+import ScrollToTop from "./components/ScrollToTop";
const cookies = new Cookies();
@@ -74,11 +75,16 @@ render(
{({ isAuthenticated }) =>
isAuthenticated ? (
<AppRoot>
- <Switch>
- <Route path="/categories" component={CategorySection} />
- <Route path="/pages" component={PageSection} />
- <Route path="/products" component={ProductSection} />
- </Switch>
+ <ScrollToTop>
+ <Switch>
+ <Route
+ path="/categories"
+ component={CategorySection}
+ />
+ <Route path="/pages" component={PageSection} />
+ <Route path="/products" component={ProductSection} />
+ </Switch>
+ </ScrollToTop>
</AppRoot>
) : (
<Route component={Auth} />