Overlays
Dialog
A modal dialog on the native <dialog> element: browser top layer, inert background, focus return and a scroll lock that is safe across nested dialogs and micro-frontends.
import { Dialog } from '@reactloom/ui';Examples
Form dialog
import { Button, Dialog, Input, Stack } from '@reactloom/ui';
export default function Example() {
return (
<Dialog.Root>
<Dialog.Trigger>Edit profile</Dialog.Trigger>
<Dialog.Content>
<Dialog.Header>
<Dialog.Title>Edit profile</Dialog.Title>
<Dialog.Description>Changes are visible to everyone in your workspace.</Dialog.Description>
</Dialog.Header>
<Dialog.Body>
<Stack gap="4">
<Input label="Full name" defaultValue="Ada Lovelace" />
<Input label="Job title" defaultValue="Principal engineer" />
</Stack>
</Dialog.Body>
<Dialog.Footer>
<Dialog.Close>Cancel</Dialog.Close>
<Button>Save changes</Button>
</Dialog.Footer>
</Dialog.Content>
</Dialog.Root>
);
}Confirmation
role="alertdialog" with initial focus on the safe action.
import { Dialog } from '@reactloom/ui';
import { useRef } from 'react';
export default function Example() {
const cancelRef = useRef<HTMLButtonElement>(null);
return (
<Dialog.Root>
<Dialog.Trigger variant="destructive">Delete project</Dialog.Trigger>
<Dialog.Content role="alertdialog" size="sm" initialFocusRef={cancelRef} showCloseButton={false}>
<Dialog.Header>
<Dialog.Title>Delete “Apollo”?</Dialog.Title>
<Dialog.Description>This permanently removes 128 files and cannot be undone.</Dialog.Description>
</Dialog.Header>
<Dialog.Footer>
<Dialog.Close ref={cancelRef}>Cancel</Dialog.Close>
<Dialog.Close variant="destructive">Delete project</Dialog.Close>
</Dialog.Footer>
</Dialog.Content>
</Dialog.Root>
);
}Controlled
Refuse to close while saving.
import { Button, Dialog, Input } from '@reactloom/ui';
import { useState } from 'react';
export default function Example() {
const [open, setOpen] = useState(false);
const [saving, setSaving] = useState(false);
const save = () => {
setSaving(true);
setTimeout(() => {
setSaving(false);
setOpen(false);
}, 1200);
};
return (
<>
<Button variant="secondary" onClick={() => setOpen(true)}>Rename workspace</Button>
{/* Refuse to close while saving: every dismissal goes through onOpenChange. */}
<Dialog.Root open={open} onOpenChange={(next) => !saving && setOpen(next)}>
<Dialog.Content size="sm">
<Dialog.Header>
<Dialog.Title>Rename workspace</Dialog.Title>
</Dialog.Header>
<Dialog.Body>
<Input label="Workspace name" defaultValue="Acme" />
</Dialog.Body>
<Dialog.Footer>
<Dialog.Close disabled={saving}>Cancel</Dialog.Close>
<Button loading={saving} loadingText="Saving" onClick={save}>Save</Button>
</Dialog.Footer>
</Dialog.Content>
</Dialog.Root>
</>
);
}API reference
Dialog.Root
| Prop | Type | Default |
|---|---|---|
open / defaultOpen | boolean | — |
onOpenChangeEvery dismissal path goes through it. | (open: boolean) => void | — |
Dialog.Content
| Prop | Type | Default |
|---|---|---|
size | 'sm' | 'md' | 'lg' | 'xl' | 'full' | 'md' |
role | 'dialog' | 'alertdialog' | 'dialog' |
closeOnEscape | boolean | true |
closeOnBackdropClick | boolean | true (false for alertdialog) |
initialFocusRef / finalFocusRef | RefObject<HTMLElement> | — |
showCloseButton · closeLabel | boolean · string | true · 'Close' |
keepMounted | boolean | false |
classNames | { root, panel, closeButton } | — |
Parts
| Prop | Type | Default |
|---|---|---|
Trigger · CloseButtons; asChild for your own element. | ButtonProps | — |
Title · DescriptionName and describe the dialog. | | — |
Header · Body · FooterLayout; Body scrolls. | | — |
Customization
Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.
Slot class names
Add classes to inner parts with classNames (className is shorthand for root): root, panel, closeButton.
CSS variables
| Variable | Default |
|---|---|
--pl-dialog-radius | var(--pl-radius-xl |
--pl-dialog-width | 25rem |
--pl-dialog-width | 35rem |
--pl-dialog-width | 45rem |
--pl-dialog-width | 60rem |
State attributes
Target these in your CSS to style states without depending on class names.
| Attribute | Values |
|---|---|
[data-size] | sm · md · lg · xl · full |
Theme tokens it reads
--pl-color-bg-overlay --pl-color-bg-surface-raised --pl-color-border-default --pl-color-fg-default --pl-color-fg-muted --pl-radius-xl --pl-shadow-lg
Accessibility
- Background content is inert — unreachable by keyboard and by the screen-reader virtual cursor.
- Focus starts on the dialog (title and description are announced) or on initialFocusRef; it returns to the trigger.
- Escape closes the top-most dialog only.
| Key | Action |
|---|---|
| Tab / Shift+Tab | Cycle focus inside the dialog |
| Escape | Close |
Usage guidelines
Do
- Always render a Dialog.Title.
- Use alertdialog for destructive confirmations.
Don’t
- Don’t open a dialog on page load.
- Don’t put long forms in dialogs — use a page.