diff --git a/apps/formbricks-com/components/docs/Layout.tsx b/apps/formbricks-com/components/docs/Layout.tsx index 0bdcd471e8..ac62162cd1 100644 --- a/apps/formbricks-com/components/docs/Layout.tsx +++ b/apps/formbricks-com/components/docs/Layout.tsx @@ -12,6 +12,7 @@ import { useRouter } from "next/router"; import { useEffect, useState } from "react"; import MetaInformation from "../shared/MetaInformation"; import DocsFeedback from "./DocsFeedback"; +import { useRef } from "react"; function GitHubIcon(props: any) { return ( @@ -92,6 +93,23 @@ export const Layout: React.FC = ({ children, meta }) => { let nextPage = allLinks[linkIndex + 1]; let section = navigation.find((section) => section.links.find((link) => link.href === router.pathname)); + const linkRef = useRef(null); + const parentRef = useRef(null); + + const preserveScroll = () => { + const scroll = Math.abs(linkRef.current.getBoundingClientRect().top - linkRef.current.offsetTop); + sessionStorage.setItem("scrollPosition", (scroll + 89).toString()); + }; + + useEffect(() => { + if (parentRef.current) { + const scrollPosition = Number.parseInt(sessionStorage.getItem("scrollPosition"), 10); + if (scrollPosition) { + parentRef.current.scrollTop = scrollPosition; + } + } + }, []); + return ( <> = ({ children, meta }) => {
-
- +
+
diff --git a/apps/formbricks-com/components/shared/Navigation.tsx b/apps/formbricks-com/components/shared/Navigation.tsx index 8bb2d109ea..0befd0b566 100644 --- a/apps/formbricks-com/components/shared/Navigation.tsx +++ b/apps/formbricks-com/components/shared/Navigation.tsx @@ -11,9 +11,11 @@ interface NavigationProps { }[]; }[]; className: string; + preserveScroll: () => void; + linkRef: React.RefObject; } -export function Navigation({ navigation, className }: NavigationProps) { +export function Navigation({ navigation, className, preserveScroll, linkRef }: NavigationProps) { let router = useRouter(); return ( @@ -26,8 +28,9 @@ export function Navigation({ navigation, className }: NavigationProps) { role="list" className="mt-2 space-y-2 border-l-2 border-slate-100 dark:border-slate-800 lg:mt-4 lg:space-y-4 lg:border-slate-200"> {section.links.map((link) => ( -
  • +