Examples

Form dialog

Preview
Example.tsx
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.

Preview
Example.tsx
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.

Preview
Example.tsx
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

Dialog.Root
PropTypeDefault
open / defaultOpen
boolean—
onOpenChange
Every dismissal path goes through it.
(open: boolean) => void—

Dialog.Content

Dialog.Content
PropTypeDefault
size
'sm' | 'md' | 'lg' | 'xl' | 'full''md'
role
'dialog' | 'alertdialog''dialog'
closeOnEscape
booleantrue
closeOnBackdropClick
booleantrue (false for alertdialog)
initialFocusRef / finalFocusRef
RefObject<HTMLElement>—
showCloseButton · closeLabel
boolean · stringtrue · 'Close'
keepMounted
booleanfalse
classNames
{ root, panel, closeButton }—

Parts

Parts
PropTypeDefault
Trigger · Close
Buttons; asChild for your own element.
ButtonProps—
Title · Description
Name and describe the dialog.
—
Header · Body · Footer
Layout; 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

VariableDefault
--pl-dialog-radiusvar(--pl-radius-xl
--pl-dialog-width25rem
--pl-dialog-width35rem
--pl-dialog-width45rem
--pl-dialog-width60rem

State attributes

Target these in your CSS to style states without depending on class names.

AttributeValues
[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.
Keyboard interactions
KeyAction
Tab / Shift+TabCycle focus inside the dialog
EscapeClose

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.