ScrollLock
Stops the page behind from scrolling while a panel of its own is open. The scrollbar keeps its room, so nothing slides sideways.
import { ScrollLock } from '@sypnia/ui/react'
On this page
Lock and release
Code
import { useState } from 'react';
import { Button, ScrollLock } from '@sypnia/ui/react';
// Lock it, then try to scroll the page: it stays. The scrollbar keeps its room, so nothing moves sideways.
export default function Lock() {
const [on, setOn] = useState(false);
return <><ScrollLock active={on} /><Button aria-pressed={on} onClick={() => setOn(!on)}>{on ? 'Let the page scroll' : 'Lock the page'}</Button></>;
} When to use it
Use it when
- A full-screen panel of your own.
Do not use it when
- Dialogs and drawers: they lock already.
For everyone
- Nothing is announced; the content behind is still reachable unless it is also made inert.
Props
| ScrollLock | Type | Default |
|---|---|---|
active | boolean | true |