Skip to Content
BBRICKSv0.7.4
DataInterface hooks

useModalLock

While a modal (the video drawer) is open, the page behind it is out of reach (QA #675 N14): the body does not scroll, and the app root is inert (no focus, no clicks) and aria-hidden (a screen reader stays in the dialog). Set on the element itself, not as React props: React 18 has no inert prop, and an attribute React does not own is never reset on a re-render. Everything is put back as it was when the modal closes or the component unmounts.

import { useModalLock } from '@ergasti/bricks';

Examples

Lock the page behind an overlay

While open, the body does not scroll and the app root you point at is inert and aria-hidden; all of it is put back on close. The hook is called with a ref to the root of the page behind.

Code
import { useRef, useState } from 'react';
import { Button, useModalLock } from '@ergasti/bricks';

function Lock() {
  const [open, setOpen] = useState(false);
  const rootRef = useRef<HTMLDivElement>(null);
  useModalLock(open, rootRef);
  return (
    <div>
      <div ref={rootRef}><p>The app root: inert while the overlay is open.</p><Button onClick={() => setOpen(true)}>Open overlay</Button></div>
      {open && <div role="dialog" aria-label="Overlay" style={{ marginTop: 10, padding: 14, borderRadius: 14, background: 'var(--card)', border: '1px solid var(--line)' }}><Button size="sm" onClick={() => setOpen(false)}>Close overlay</Button></div>}
    </div>
  );
}

Signature

function useModalLock(open: boolean, rootRef: RefObject<HTMLElement | null>): void

Parameters

Prop

Type

Returns

void

Button · useDebouncedValue · useFocusTrap · useIsMobile · useOpenedRow

Source

src/hooks/useModalLock.ts (line 10) on GitHub.

On this page