# Dialog

Modal content with focus management and composable actions.

Modal content with focus management and composable actions.

<p className="zenos-base-ui-source">
  Backed by <a href="https://base-ui.com/react/components/dialog">Base UI Dialog</a> for upstream
  behavior and configuration. Zenos owns the public API, styling, and composition shown on this
  page.
</p>

```tsx
import { Dialog, Field, Input, Stack, Textarea } from "@zentara-co/zenos-ui";

function DialogExample() {
  return (
    <Dialog.Root>
      <Dialog.Trigger variant="primary">Edit workspace</Dialog.Trigger>
      <Dialog.Content>
        <Dialog.Header>
          <Dialog.Title>Edit workspace</Dialog.Title>
          <Dialog.Description>Update shared workspace settings.</Dialog.Description>
        </Dialog.Header>
        <Stack gap="4">
          <Field.Root required>
            <Field.Label>Workspace name</Field.Label>
            <Field.Control render={<Input defaultValue="Security operations" />} />
            <Field.Description>This name is visible to every workspace member.</Field.Description>
          </Field.Root>
          <Field.Root>
            <Field.Label>Summary</Field.Label>
            <Field.Control render={<Textarea placeholder="What is this workspace used for?" />} />
          </Field.Root>
        </Stack>
        <Dialog.Footer>
          <Dialog.Close variant="primary">Cancel</Dialog.Close>
          <Dialog.Close variant="primary">Save changes</Dialog.Close>
        </Dialog.Footer>
      </Dialog.Content>
    </Dialog.Root>
  );
}
```

```text
Dialog.Root
├── Dialog.Trigger
└── Dialog.Content
    ├── Dialog.Header
    │   ├── Dialog.Title
    │   └── Dialog.Description
    ├── Content
    └── Dialog.Footer
        └── Dialog.Close
```

## Import

```tsx
import { Dialog } from "@zentara-co/zenos-ui";
```

## Composition and actions

`Dialog.Trigger` and `Dialog.Close` are already styled buttons. Use their `variant` and `size`
props for standard controls. Use Base UI's `render` composition only when another ref-forwarding
component must own the rendered element.

Use `Dialog.Close` for actions that always dismiss, such as Cancel or Done. For work that can fail
or finish asynchronously, use a regular Button and update the controlled `open` state only after
the operation succeeds.

## Controlled state

Use `open` and `onOpenChange` when application state must observe every opening and closing path.
The example closes from application code after saving while Cancel, Escape, and allowed outside
interaction continue through `onOpenChange`.

```tsx
import { Button, Dialog, Field, Input, Stack, Text } from "@zentara-co/zenos-ui";
import { useState } from "react";

function DialogControlledExample() {
  const [open, setOpen] = useState(false);
  const [saved, setSaved] = useState(false);

  return (
    <Stack gap="3" align="start">
      <Dialog.Root open={open} onOpenChange={setOpen}>
        <Dialog.Trigger variant="primary">Edit profile</Dialog.Trigger>
        <Dialog.Content>
          <Dialog.Header>
            <Dialog.Title>Edit profile</Dialog.Title>
            <Dialog.Description>Update the name shown to workspace members.</Dialog.Description>
          </Dialog.Header>
          <Field.Root>
            <Field.Label>Display name</Field.Label>
            <Field.Control render={<Input defaultValue="Alex Morgan" />} />
          </Field.Root>
          <Dialog.Footer>
            <Dialog.Close variant="ghost">Cancel</Dialog.Close>
            <Button
              onClick={() => {
                setSaved(true);
                setOpen(false);
              }}
            >
              Save changes
            </Button>
          </Dialog.Footer>
        </Dialog.Content>
      </Dialog.Root>
      <Text size="s" color="subtle" aria-live="polite">
        {saved ? "Profile saved." : `Dialog is ${open ? "open" : "closed"}.`}
      </Text>
    </Stack>
  );
}
```

## Dismissal behavior

Dialogs dismiss from their trigger, Close controls, Escape, and outside presses by default. Set
`disablePointerDismissal` when an accidental outside press would interrupt important work. Escape
and explicit Close controls remain available.

```tsx
import { Dialog, Text } from "@zentara-co/zenos-ui";

function DialogDismissalExample() {
  return (
    <Dialog.Root disablePointerDismissal>
      <Dialog.Trigger variant="primary">Review policy</Dialog.Trigger>
      <Dialog.Content showCloseButton={false}>
        <Dialog.Header>
          <Dialog.Title>Updated access policy</Dialog.Title>
          <Dialog.Description>
            Outside presses are disabled so this decision is not dismissed accidentally.
          </Dialog.Description>
        </Dialog.Header>
        <Text>
          Administrators must now review requests before members can access protected resources.
        </Text>
        <Dialog.Footer>
          <Dialog.Close variant="primary">Not now</Dialog.Close>
          <Dialog.Close variant="primary">I understand</Dialog.Close>
        </Dialog.Footer>
      </Dialog.Content>
    </Dialog.Root>
  );
}
```

Set `showCloseButton={false}` only when another clearly labeled `Dialog.Close` is always present.
Use AlertDialog instead when a destructive or irreversible action requires an explicit decision.

## Width and surface styling

The default surface is `max-w-lg`. Override dimensions and padding through `className` on
`Dialog.Content`. Use `overlayClassName` for the backdrop and `viewportClassName` for viewport
spacing or alignment. Prefer semantic tokens for the dialog surface itself.

The backdrop still renders when the dialog is nested inside another dialog, including a closed
sheet. `Dialog.Overlay` uses `forceRender` for that case. Pass `forceRender={false}` only when a
nested dialog should leave the page undimmed.

```tsx
import { Card, Dialog, Grid, Text } from "@zentara-co/zenos-ui";

function DialogCustomSurfaceExample() {
  return (
    <Dialog.Root>
      <Dialog.Trigger variant="primary">Open audit summary</Dialog.Trigger>
      <Dialog.Content
        className="max-w-2xl border-border-brand p-6 xl:p-8"
        overlayClassName="bg-black/60 backdrop-blur-sm"
        viewportClassName="px-6 py-10"
        closeLabel="Close audit summary"
      >
        <Dialog.Header>
          <Dialog.Title>Audit summary</Dialog.Title>
          <Dialog.Description>A wider surface for information-dense workflows.</Dialog.Description>
        </Dialog.Header>
        <Grid columns={{ base: 1, sm: 2 }} gap="3">
          <Card>
            <Card.Content>
              <Text weight="medium">Authentication</Text>
              <Text size="s" color="subtle">
                24 controls passing
              </Text>
            </Card.Content>
          </Card>
          <Card>
            <Card.Content>
              <Text weight="medium">Data protection</Text>
              <Text size="s" color="subtle">
                18 controls passing
              </Text>
            </Card.Content>
          </Card>
        </Grid>
        <Dialog.Footer>
          <Dialog.Close>Done</Dialog.Close>
        </Dialog.Footer>
      </Dialog.Content>
    </Dialog.Root>
  );
}
```

## Scrollable content

Enable `scrollable` for content that may exceed the viewport. Dialog constrains the surface to 90%
of the viewport height and creates an internal scroll region. Headers, body content, and footers
inside that region scroll together.

```tsx
import { Card, Dialog, Stack } from "@zentara-co/zenos-ui";

function DialogScrollableExample() {
  return (
    <Dialog.Root>
      <Dialog.Trigger variant="primary">Review activity</Dialog.Trigger>
      <Dialog.Content scrollable showCloseButton={false}>
        <Dialog.Header className="pb-4">
          <Dialog.Title>Workspace activity</Dialog.Title>
          <Dialog.Description>Recent changes across this workspace.</Dialog.Description>
        </Dialog.Header>
        <Stack gap="3">
          {Array.from({ length: 12 }, (_, index) => (
            <Card key={index}>
              <Card.Content className="text-sm">
                Activity {index + 1}: Security policy updated by a workspace administrator.
              </Card.Content>
            </Card>
          ))}
        </Stack>
        <Dialog.Footer className="mt-6 border-t border-border-default pt-4">
          <Dialog.Close>Done</Dialog.Close>
        </Dialog.Footer>
      </Dialog.Content>
    </Dialog.Root>
  );
}
```

## Focus management

Focus moves to the first tabbable element when the dialog opens and returns to its trigger when it
closes. Pass `initialFocus` or `finalFocus` to `Dialog.Content` only when the default order is not
appropriate. Avoid initially focusing a destructive action.

`Dialog.Content` creates the portal, overlay, viewport, and popup while preserving Base UI focus
trapping, Escape handling, outside interaction, and focus return. Use its styling props instead of
wrapping Content in another portal or overlay.

## Anatomy

```text
Dialog.Root
Dialog.Trigger
Dialog.Content
Dialog.Header
Dialog.Title
Dialog.Description
Dialog.Footer
Dialog.Close
```

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| open | boolean | — | Controlled open state. |
| defaultOpen | boolean | false | Initial uncontrolled open state. |
| onOpenChange | (open: boolean, eventDetails) => void | — | Runs for trigger, Close, Escape, outside press, and controlled changes. |
| onOpenChangeComplete | (open: boolean) => void | — | Runs after opening or closing animations finish. |
| modal | boolean \| trap-focus | true | Controls focus trapping, page scroll locking, and outside interaction. |
| disablePointerDismissal | boolean | false | Prevents outside pointer presses from closing the dialog. |
| render (Trigger / Close) | ReactElement \| function | — | Composes Trigger and Close with another element. |
| initialFocus / finalFocus (Content) | Ref \| function | — | Customizes entry and return focus. |
| scrollable (Content) | boolean | false | Constrains tall content and enables internal overflow scrolling. |
| showCloseButton (Content) | boolean | true | Shows the automatic icon close control. |
| closeLabel (Content) | string | Close | Accessible name for the automatic close control. |
| variant / size (Trigger / Close) | ButtonVariant / sm \| md \| lg | primary / md (Trigger), outline / md (Close) | Styles the built-in button controls. |
| className (Content) | string | — | Overrides popup width, spacing, and surface styling. |
| overlayClassName (Content) | string | — | Adds classes to the generated modal backdrop. |
| forceRender (Overlay) | boolean | true | Renders the backdrop when the dialog is nested inside another dialog, including a closed sheet. |
| viewportClassName (Content) | string | — | Adds classes to the generated positioning viewport. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

Give every dialog a meaningful `Dialog.Title`; add `Dialog.Description` when the scope or
consequence needs explanation. The automatic icon button uses `closeLabel`; customize it when
“Close” lacks enough context. Keep at least one explicit close path in modal dialogs, preserve a
logical tab order, and do not use Dialog as a substitute for AlertDialog confirmation semantics.

Source: https://zenos-ui.pages.dev/components/dialog/