Overlays
ModalPage
Modal panel with header, scrollable content and footer. A centered dialog on regular width and a draggable bottom sheet on compact width.
import { ModalPage, ModalPageHeader, ModalPageContent, ModalRoot } from "datui";Examples
Basic
Controlled with open and onClose(reason).
Sheet with snap points
settlingHeight opens the compact sheet at that height; it can be dragged up or swiped down.
ModalRoot
Shows one child modal by activeModal id; each child is still an ordinary controlled modal.
Accessibility
- Renders
role="dialog"witharia-modal="true", labelled by theModalPageHeadertitle (anh2by default). - Focus moves into the dialog on open, is trapped while open and returns to the previously focused element on close.
- Escape, an overlay click, the close button and (compact) a swipe down close it;
preventCloseblocks all of them. - Page scroll is locked and content outside the dialog is hidden from assistive technology while it is open.
ModalPageContentis a focusable scroll region so keyboard users can scroll long content.
API
ModalPage
Modal panel with header, scrollable content and footer. A centered dialog on regular width and a draggable bottom sheet on compact width.
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | — | |
| closeLabel | string | Close | |
| disableAnimation | boolean | — | |
| disableOverlay | boolean | — | Keep the overlay transparent (it still blocks the page). |
| footer | ReactNode | — | |
| header | ReactNode | — | Usually a `ModalPageHeader`; its title labels the dialog. |
| height | string | number | — | Fixed height (CSS length) on regular width. |
| hideCloseButton | boolean | false | |
| onClose | ((reason: ModalCloseReason) => void) | — | Called with the reason whenever the modal asks to close. |
| onClosed | (() => void) | — | Called after the exit animation, once the modal has unmounted. |
| onOpenChange | ((open: boolean) => void) | — | Called with `false` whenever the modal asks to close. |
| onOpened | (() => void) | — | Called once the modal has mounted. |
| open | boolean | false | |
| outsideButtons | ReactNode | — | Extra round buttons shown above the sheet on compact width (see `ModalOutsideButton`). |
| preventClose | boolean | — | Block Escape, overlay click, swipe-down and hide the close button. |
| restoreFocus | RestoreFocus | true | |
| settlingHeight | 25 | 50 | 75 | 100 | — | Initial height of the compact sheet in percent of the viewport. Below 100 the sheet gets two snap points (this height and full height) and can be dragged between them. Unset, the sheet fits its content. |
| size | string | number | s | Max width on regular width: a preset or any CSS length. |
ModalPageHeader
Title bar of a `ModalPage`. The title becomes the dialog's accessible name.
| Prop | Type | Default | Description |
|---|---|---|---|
| after | ReactNode | — | Content at the end, e.g. an action button. |
| before | ReactNode | — | Content at the start, e.g. a back button. |
| className | string | — | |
| noSeparator | boolean | false | |
| titleAs | ElementType<any, keyof IntrinsicElements> | h2 | Element for the title; it labels the dialog. |
ModalPageContent
Scrollable body of a `ModalPage`. It is focusable so keyboard users can scroll it; on compact width the sheet only starts dragging when this area is scrolled to the top.
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | — |
ModalRoot
Shows one of its child modals by id. Each child is an ordinary controlled modal; ModalRoot only sets its `open` and forwards `onClose`, so a plain `open` state per modal works just as well.
| Prop | Type | Default | Description |
|---|---|---|---|
| activeModal | string | null | `id` of the child modal to show; `null` shows none. |
| children | ReactNode | — | `ModalPage` / `ModalCard` elements, each with a unique `id`. |
| onClose | ((id: string, reason: ModalCloseReason) => void) | — | Called with the active modal's id when it asks to close. |