@oslokommune/punkt-react
Version:
React komponentbibliotek til Punkt, et designsystem laget av Oslo Origo
25 lines (24 loc) • 1.15 kB
TypeScript
/**
* Shared body scroll-lock used by every overlay in the design system (modal,
* service/global header menus, search and user dropdowns).
*
* Strategy: an iOS-safe `position: fixed` lock — `overflow: hidden` alone is
* ignored by iOS Safari. The current scroll position is saved, the body is
* pinned, scrollbar width is reserved to avoid a layout shift, and the scroll
* position is restored on release.
*
* Reference-counted so several open overlays don't unlock the page when one of
* them closes. Each caller holds a token (see {@link createScrollLockToken}) so
* repeated lock/unlock calls from the same source are idempotent — only the
* first lock and the last unlock touch the DOM.
*/
export interface ScrollLockToken {
locked: boolean;
}
export declare const createScrollLockToken: () => ScrollLockToken;
/**
* Lock or unlock body scroll for a single source. Pass a token created with
* {@link createScrollLockToken} so the call is idempotent — locking an already
* locked token (or unlocking an unlocked one) is a no-op.
*/
export declare const setScrollLock: (token: ScrollLockToken, shouldLock: boolean) => void;