diff --git a/client/src/app.scss b/client/src/app.scss index ab22faaba672..3926046acbcf 100644 --- a/client/src/app.scss +++ b/client/src/app.scss @@ -122,11 +122,13 @@ } } -:target { +:target, +section[id] { scroll-margin-top: var(--sticky-header-with-actions-height); } -.sticky-header-container.without-actions ~ * :target { +.sticky-header-container.without-actions ~ * :target, +.sticky-header-container.without-actions ~ * section[id] { scroll-margin-top: var(--sticky-header-without-actions-height); } diff --git a/client/src/hooks.ts b/client/src/hooks.ts index 1e042cbabe36..b6c9cedb235b 100644 --- a/client/src/hooks.ts +++ b/client/src/hooks.ts @@ -255,3 +255,17 @@ export function useIsIntersecting( }, [node, options]); return isIntersectingState; } + +export const useScrollToAnchor = () => { + const scrolledRef = React.useRef(false); + const { hash } = useLocation(); + React.useEffect(() => { + if (hash && !scrolledRef.current) { + const element = document.getElementById(hash.replace("#", "")); + if (element) { + element.scrollIntoView({ behavior: "instant" }); + scrolledRef.current = true; + } + } + }); +}; diff --git a/client/src/plus/offer-overview/index.tsx b/client/src/plus/offer-overview/index.tsx index 2db6da3aff71..d8b742d706a5 100644 --- a/client/src/plus/offer-overview/index.tsx +++ b/client/src/plus/offer-overview/index.tsx @@ -1,8 +1,10 @@ +import { useScrollToAnchor } from "../../hooks"; import OfferHero from "./offer-hero"; import OfferOverviewFeatures from "./offer-overview-feature"; import OfferOverviewSubscribe from "./offer-overview-subscribe"; function OfferOverview() { + useScrollToAnchor(); return (
diff --git a/client/src/settings/index.tsx b/client/src/settings/index.tsx index 95e3e763034c..dfe55eb52082 100644 --- a/client/src/settings/index.tsx +++ b/client/src/settings/index.tsx @@ -7,11 +7,13 @@ import "./index.scss"; import { Manage } from "./manage"; import Newsletter from "./newsletter"; import { ManageAIHelp } from "./ai-help"; +import { useScrollToAnchor } from "../hooks"; const OfflineSettings = React.lazy(() => import("./offline-settings")); export function Settings() { const pageTitle = "Settings"; + useScrollToAnchor(); return ( <>