Skip to content

useOverlay

Shared full-screen overlay behavior: Escape-to-close + body scroll lock. Used internally by LxModal / LxDrawer.

Usage

ts
import { useOverlay } from '@luxeanor/ui'

// open can be a Ref<boolean> or () => boolean
useOverlay(() => props.modelValue, close)

API

useOverlay(open: Ref<boolean> | (() => boolean), close: () => void): void

Behavior & boundaries:

  • open turns true: listens for Escape, locks body scroll; turns false: releases both
  • The scroll lock is reference-counted — stacked overlays (Drawer over Modal) don't unlock early
  • Auto-unlocks on unmount if still open
  • SSR-safe (never touches document on the server)