DOM & Events

useScrollLock

Lock and unlock body scroll for modals and overlays with proper cleanup.

import { useScrollLock } from "saha-ui"

Uses

Lock body scrolling (and compensate for scrollbar width) for overlays like modals and drawers.

Props

NameTypeDescriptionDefault
isLockedbooleanLock state.-

Returns

NameDescription
voidNo return value; performs side effects on `document.body`.

Example

useScrollLock(isModalOpen);

Notes

Stores original overflow and paddingRight and restores them on cleanup; calculates scrollbar width to prevent layout shift.
Saha UI - The Modern React Component Library