From 7bc86b066f1c9d31970c52de55f32440a1274c41 Mon Sep 17 00:00:00 2001 From: Mikael Brevik Date: Fri, 13 Dec 2024 12:01:15 +0100 Subject: [PATCH] fix: scroll to top --- src/components/navigation/header/Header.tsx | 2 ++ src/utils/hooks/useScrollToTop.ts | 7 +++++++ 2 files changed, 9 insertions(+) create mode 100644 src/utils/hooks/useScrollToTop.ts diff --git a/src/components/navigation/header/Header.tsx b/src/components/navigation/header/Header.tsx index 412f3630a..23abaaa6b 100644 --- a/src/components/navigation/header/Header.tsx +++ b/src/components/navigation/header/Header.tsx @@ -11,6 +11,7 @@ import LanguageSwitcher from "src/components/languageSwitcher/LanguageSwitcher"; import CustomLink from "src/components/link/CustomLink"; import LinkButton from "src/components/linkButton/LinkButton"; import useScrollDirection from "src/utils/hooks/useScrollDirection"; +import useScrollToTop from "src/utils/hooks/useScrollToTop"; import { getHref } from "src/utils/link"; import { Announcement } from "studio/lib/interfaces/announcement"; import { BrandAssets } from "studio/lib/interfaces/brandAssets"; @@ -45,6 +46,7 @@ export const Header = ({ const [isOpen, setIsOpen] = useState(false); const sidebarData = navigation.sidebar || navigation.main; + useScrollToTop(); const scrollDirection = useScrollDirection(); const links = filterLinks(navigation.main, linkID); diff --git a/src/utils/hooks/useScrollToTop.ts b/src/utils/hooks/useScrollToTop.ts new file mode 100644 index 000000000..a8ad8e099 --- /dev/null +++ b/src/utils/hooks/useScrollToTop.ts @@ -0,0 +1,7 @@ +import { useEffect } from "react"; + +export default function useScrollToTop() { + useEffect(() => { + window.scrollTo({ top: 0, behavior: "instant" }); + }, []); +}