UI

Dialog

A focused modal surface for decisions, forms, and confirmations.

import { Dialog } from '@uthereal/ui/dialog'

Dialog playground

Loading interactive preview…

Overview

Dialog renders a centered modal surface opened by a trigger or controlled open state. It requires a title, accepts an optional description, renders children in the body, and supports up to three end-aligned footer actions. While open, focus stays trapped inside, the page behind is inert (except live regions), page scroll locks, and closing returns focus to the trigger.

The surface has a header band (title, description, and a 32 px corner close button on the title line with a 40 px coarse-pointer target), a hairline divider, a separately padded body and footer, and a 7 px blurred backdrop. Changing title or description while open crossfades the text with a soft blur and vertical rise.

Use Dialog for short tasks or confirmations that must block the page until completed. Set role="alertdialog" with closeOnInteractOutside={false} for destructive or irreversible confirmations. Use Drawer or Bottom sheet for edge-anchored panels.

Usage

'use client'
import { Dialog } from '@uthereal/ui/dialog'
import { TextInput } from '@uthereal/ui/text-input'

export function RenameProject() {
  return (
    <Dialog
      title="Rename project"
      description="The new name is visible to everyone in the workspace."
      trigger={{ label: 'Rename project', icon: 'pencil' }}
      actions={[
        { id: 'cancel', label: 'Cancel' },
        { id: 'save', label: 'Save name', action: 'save_name' },
      ]}
      onAction={(action, itemId) => console.log(action, itemId)}
    >
      <TextInput label="Project name" defaultValue="Quarterly report" />
    </Dialog>
  )
}

onAction receives the activated item's action name and id. Your application implements the effect.

Confirmation dialogs (role="alertdialog")

Set role="alertdialog" to announce the title and description as an urgent confirmation. Pair it with closeOnInteractOutside={false} so users make an explicit choice, set tone: 'danger' on destructive confirmations, and put autoFocus: true on the safest default action.

'use client'
import { Dialog } from '@uthereal/ui/dialog'

export function DeleteProject({ onDelete }: { onDelete: () => void }) {
  return (
    <Dialog
      role="alertdialog"
      width="sm"
      title="Delete this project?"
      description="All 12 reports in it are removed for everyone. This cannot be undone."
      closeOnInteractOutside={false}
      trigger={{ label: 'Delete project', icon: 'trash-2', tone: 'danger' }}
      actions={[
        { id: 'cancel', label: 'Keep project', autoFocus: true },
        {
          id: 'delete',
          label: 'Delete project',
          action: 'delete_project',
          tone: 'danger',
        },
      ]}
      onAction={(action) => {
        if (action === 'delete_project') onDelete()
      }}
    />
  )
}

Examples

Widths

sm, md, lg, and xl map to 400, 440 (default), 640, and 800 px. The surface clamps to the viewport with a 16 px margin on small screens and scrolls internally when taller than the viewport.

Actions and confirmations

Footer actions align to the inline end. The last action confirms by default (variant="solid", tone="accent"); earlier actions default to variant="outline" and tone="neutral". Override tone (for example tone: 'danger') or variant per action. Each action closes the dialog after activation unless close: false is set, and at most one action may set autoFocus: true.

Loading and triggerless usage

For asynchronous work, set close: false on the confirming action, toggle loading while work runs, and close via controlled open once complete. While loading is true, Escape, backdrop clicks, and the close button are blocked, the last action displays a spinner and announces loadingLabel, and all other actions are disabled.

const [open, setOpen] = useState(false)
const [saving, setSaving] = useState(false)

<Dialog
  title="Rename project"
  open={open}
  onOpenChange={setOpen}
  loading={saving}
  loadingLabel="Saving"
  actions={[
    { id: 'cancel', label: 'Cancel' },
    { id: 'save', label: 'Save name', action: 'save_name', close: false },
  ]}
  onAction={async () => {
    setSaving(true)
    await save()
    setSaving(false)
    setOpen(false)
  }}
/>

Pass renderTrigger={null} to omit the trigger and drive visibility solely through open and onOpenChange. Focus then returns to the previously focused element on close. Nested overlays (tooltips, popovers, menus, dialogs) render inside the modal layer and stack above it, with Escape closing the topmost layer first.

API reference

These serializable arguments and defaults come directly from the component schema.

ArgumentType / defaultDescription
titleRequiredstring—Heading of the dialog, required: it names the dialog for assistive technology.
descriptionstring—Supporting text under the title, announced when the dialog opens.
roledialog | alertdialogDefault: "dialog"ARIA role of the surface. Use alertdialog for a confirmation the page announces; then give the confirming action autoFocus and tone danger for destructive confirmations.
triggerOverlayTriggerDefault: {"label":"Open dialog","variant":"outline","tone":"neutral","size":"md"}The button that opens the dialog when no React trigger is supplied: label, optional icon, variant, tone and size.
widthsm | md | lg | xlDefault: "md"Surface width: 400, 440 (the default, as Arc), 640 or 800 pixels, never wider than the viewport.
actionsDialogAction[]Default: []Up to three footer buttons, end-aligned. The last is the confirming action: solid and accent unless set; the others are outline and neutral. close (default true) closes the dialog after activation; autoFocus gives one action the initial focus.
closeOnEscapebooleanDefault: trueEscape closes the dialog. Turn it off, with closeOnInteractOutside, for dialogs that need an explicit choice.
closeOnInteractOutsidebooleanDefault: trueA press on the backdrop closes the dialog.
showClosebooleanDefault: trueShow a close button in the header, on the title line.
closeLabelstringDefault: "Close dialog"Accessible name of the close button, e.g. "Close dialog".
loadingbooleanDefault: falseWork in progress: Escape, the backdrop and the close button do nothing, the last action shows a spinner and the others are disabled.
loadingLabelstringDefault: "Loading"Announced politely while loading, e.g. "Saving".
defaultOpenbooleanDefault: falseInitial open state. Later argument edits do not reset an existing instance.
recipestudio | softDefault: "studio"Visual treatment. Both recipes use the same interaction behavior.
themeDialogTheme—Color mode, accent, and modal tokens (padding, titleSize, backdropBlur, sheetRadius, surfaceRadius, overlay, borderStrong). See Theming for all keys and defaults.
motionnone | subtle | expressiveDefault: "subtle"Modal animation preset. System reduced-motion preferences take precedence.
motionOptionsDialogMotionOptions—Modal transition, and entrance and exit poses. Exits run faster than entrances. Durations are milliseconds.
dirltr | rtl—Reading direction. Omit it to inherit the page direction.

icon arguments accept names from the icon list.

React integration

PropPurpose
refForwarded to the portalled dialog surface HTMLDivElement.
childrenDialog body rendered between the header and footer.
onAction(action, itemId)Receives the named action and action ID on footer button activation.
open / onOpenChange(open)Controlled open state and change callback.
footerCustom footer replacing the buttons generated from actions.
renderTrigger(props, state)Custom trigger renderer; spread props onto a focusable element. Pass null to omit the trigger.
presetApplication defaults merged below instance props.
renderIcon(name, context)Custom icon renderer for slot: 'trigger' or slot: 'close'. Keep icons decorative.
tokens--ui-* CSS variables applied after the typed theme on the trigger and surface.
classNameClass name appended to the dialog surface.
portalContainerPortal target, such as an element inside a native <dialog> top layer.

Keyboard & accessibility

KeyInteraction
Enter, SpaceOpen the dialog from its trigger or activate the focused action.
Tab / Shift+TabCycle through interactive elements inside the dialog; focus wraps.
EscapeClose the dialog unless closeOnEscape is false or loading.

The surface renders with role="dialog" (or role="alertdialog") and aria-modal="true", labelled by title and described by description. Initial focus moves to the action with autoFocus: true, or to the first focusable element inside the surface (the header close button when visible). Reopening a closing dialog mid-exit ignores the reopening click as an outside press.

All spacing, borders, header alignment, and footer alignment use logical CSS properties and mirror automatically under dir="rtl". Under forced-colors: active, the dialog surface and header divider preserve visible ButtonText borders.

Motion and theming

The backdrop fades in over 240 ms while the surface rises 8 px from scale 0.96 on the smooth spring (0.4s, bounce 0) with a 160 ms opacity fade. Dismissal eases out to 4 px and scale 0.98 over 160 ms. Updating title or description while open runs a blurred vertical crossfade. motionOptions overrides the modal transition, enter, and exit poses.

Under prefers-reduced-motion: reduce, travel, scale, and blur are removed in favor of a 120 ms opacity crossfade. Setting motion="none" removes all animation immediately (0 ms).

Theme tokenCSS variableDefaultRole
padding--ui-modal-padding24pxHeader, body, and footer inner padding.
titleSize--ui-modal-title-size18pxHeading font size.
backdropBlur--ui-modal-backdrop-blur7pxBackdrop blur radius (0 disables it).
surfaceRadius--ui-surface-radiusthemeOuter dialog corner radius.
overlay--ui-overlaythemeBackdrop tint color.
surfaceRaised--ui-surface-raisedthemeDialog surface background color.

theme also accepts mode, accent, and core color, border, typography, and shadow tokens. Trigger, close, and footer buttons inherit recipe, mode, accent, motion, dir, and tokens.

Composition

In an agent composition, Dialog is a container whose children render in its body. Every action must match a host-registered action; the handler receives { componentId, itemId }.

{
  "type": "Dialog",
  "props": {
    "title": "Invite member",
    "trigger": { "label": "Invite member", "icon": "plus" },
    "actions": [
      { "id": "cancel", "label": "Cancel" },
      { "id": "invite", "label": "Send invite", "action": "send_invite" }
    ]
  },
  "children": ["email-field"]
}

On this page