# Dialog

A modal window for focused tasks, built on Base UI.

- Category: Core Elements
- Page: https://wunderui.com/components/dialog
- Tier: Free

## Install

```bash
npx wunderui-cli add dialog
```

## Import

```tsx
import { Dialog, DialogBody, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogIcon, DialogOverlay, DialogPortal, DialogProgress, DialogSurface, DialogTitle, DialogTrigger } from "@/components/ui/dialog"
```

## Minimal usage

Then use it:

```tsx
import {
  Dialog,
  DialogBody,
  DialogClose,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@/components/ui/dialog"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"

export function InviteTeammate() {
  return (
    <Dialog>
      <DialogTrigger render={<Button variant="plain" />}>Invite teammate</DialogTrigger>
      <DialogContent>
        <DialogHeader>
          <DialogTitle>Invite a teammate</DialogTitle>
          <DialogDescription>They get an email with a link to join WunderUI.</DialogDescription>
        </DialogHeader>
        <DialogBody>
          <div className="flex flex-col gap-2">
            <Label htmlFor="invite-email">Email address</Label>
            <Input id="invite-email" type="email" placeholder="name@wunderui.com" />
          </div>
        </DialogBody>
        <DialogFooter>
          <DialogClose render={<Button variant="plain" />}>Cancel</DialogClose>
          <Button>Send invite</Button>
        </DialogFooter>
      </DialogContent>
    </Dialog>
  )
}
```

Expected result: You see an Invite teammate button. It opens a window with a close button, an email field, and Cancel and Send invite buttons; Cancel, the close button or Escape closes it.

## Usage

```tsx
import {
  Dialog,
  DialogBody,
  DialogClose,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@/components/ui/dialog"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"

export function Example() {
  return (
    <Dialog>
      <DialogTrigger render={<Button variant="plain" />}>Invite teammate</DialogTrigger>
      <DialogContent>
        <DialogHeader>
          <DialogTitle>Invite a teammate</DialogTitle>
          <DialogDescription>They get an email with a link to join WunderUI.</DialogDescription>
        </DialogHeader>
        <DialogBody>
          <div className="flex flex-col gap-2">
            <Label htmlFor="invite-email">Email address</Label>
            <Input id="invite-email" type="email" placeholder="name@wunderui.com" />
          </div>
        </DialogBody>
        <DialogFooter>
          <DialogClose render={<Button variant="plain" />}>Cancel</DialogClose>
          <Button>Send invite</Button>
        </DialogFooter>
      </DialogContent>
    </Dialog>
  )
}
```

## When to use

### Use Dialog for

- A short task that needs full attention and ends with a decision, such as renaming a project or inviting a member
- A small form, a choice from a list or a read-only summary before a user carries on
- A short flow of two to four steps, such as creating a workspace

### Use something else

- [Alert Dialog](https://wunderui.com/components/alert-dialog) for confirming an action that deletes data or removes access
- [Sheet](https://wunderui.com/components/sheet) for a long form or a detail view that needs more room
- [Popover](https://wunderui.com/components/popover) for small content anchored to a control, without blocking the page

## Keyboard

The buttons are native buttons, so the browser provides focus and activation. While a modal dialog is open the page behind it is inert.

| Key | Action |
|---|---|
| `Tab` or `Shift+Tab` | Moves focus between the close button, the fields and the buttons. In a modal dialog focus stays inside, wrapping from the last element to the first. |
| `Enter` or `Space` | Presses the focused button. In a text field, Enter submits only when the field sits in a form. |
| `Escape` | Closes the dialog. A click on the backdrop closes it too, unless `disablePointerDismissal` is set. |

## Behavior

What the dialog does with focus, state, content and motion.

- **Modal:** While a modal dialog is open, the page behind it is inert and does not scroll. The window is a dialog named by its title and described by its description.
- **Focus:** Focus moves to the first focusable element when the dialog opens, or to one you choose. When it closes, focus returns to the trigger, or to a place you set.
- **Closing:** The close button, a Close wrapped footer button, Escape and a click on the backdrop all close it. You can ignore the backdrop, for example while a request runs.
- **Non-modal:** A non-modal dialog has no backdrop and no focus trap, so the page stays usable. Anchor it to the bottom right for help and side tasks.
- **Appearance:** The surface look is the default: a semibold title, a footer band and a shadow. The plain look is the earlier flat one with a lighter title, no band and no shadow.
- **Scrolling:** Long content goes into a scrollable body that scrolls up to 296 px between two rules while title and footer stay in view. Give it an aria-label so it is announced as a region.
- **Small screens:** Below the small breakpoint the dialog fills the width minus 16 px gutters and the size setting has no effect. The footer stacks with the main action on top.
- **Previews in these docs:** The window is portalled to the end of the document and fixed to the screen. The previews here draw it inside the card with the same behaviour, so it does not cover the page.
- **Opening and closing:** The window fades in and zooms from 92% while sliding up 8 px, and the backdrop fades. Closing is a step faster and zooms down to 96%.
- **Reduced motion:** With reduced motion the zoom and slide are off and the window only fades, in and out.

## Anatomy

- `Dialog`: Holds the open state and links the trigger to the window. Control it or leave it uncontrolled; it renders nothing itself.
- `DialogTrigger`: The element that opens the dialog, usually a button. Focus returns to it when the dialog closes.
- `DialogContent`: The window, with its own portal and overlay. It keeps focus inside, comes in three widths (384, 512 and 720 px) and can be non-modal and anchored to a corner.
- `Close button`: The icon button in the top right corner, named Close for screen readers. It is on by default; turn it off only when the footer offers a clear way out.
- `DialogHeader`: Stacks the progress, icon, title and description at the top, and leaves room for the close button.
- `DialogProgress`: The step indicator of a short multi-step dialog (two to four steps), with an optional label for the current step. It is exposed as a progress bar.
- `DialogIcon`: A round 40 px icon above the title in a default, warning or destructive look. Pass a Lucide icon as its child.
- `DialogTitle`: Names the dialog, and screen readers announce it when the dialog opens. A title is needed even when the design shows none.
- `DialogDescription`: One or two sentences on what the dialog is for, read out after the title.
- `DialogBody`: The slot between header and footer for a form, a list or text. When scrollable, it scrolls between two rules while title and footer stay put, and keyboard users can focus it to scroll.
- `DialogFooter`: The row of buttons, with the last one on the right and on top on a phone. It can paint a full-width band, stack the buttons, or put one action such as Back at the left edge.
- `DialogClose`: Closes the dialog. Wrap the Cancel button in it, or turn on the footer's Close button.
- `Action`: The primary Button, last in the footer. Name it after its result, such as Send invite, and show its pending state while the request runs.
- `DialogOverlay`: The dimmed, lightly blurred backdrop. DialogContent already renders it, and a click on it closes the dialog.
- `DialogPortal`: Moves the window to the end of the document. DialogContent already renders it, so you only need it for a custom window or container.
- `DialogSurface`: The same window as a static panel without portal, overlay or focus trap, for previews and embedded layouts. Give it an aria-label.
- `Footer Start`

## Best practices

### Do

- Always include a DialogTitle, even when the design shows none. Without it the dialog has no name for screen readers.
- Put the main action last and name it after its result: Send invite, Create project, not OK. Keep Cancel neutral next to it.
- On a failed submit keep the dialog open and the input, and put the message on the field or in an Alert at the top of the body.
- While the request runs, show the pending state on the primary action and disable the others. Close the dialog only after the server confirms.
- Put long content in a scrollable DialogBody so the title and footer stay in view.

### Don't

- Don't confirm a destructive action in a Dialog, since a click outside closes it. An Alert Dialog closes only through a button or Escape.
- Don't use a dialog to report that something worked. A saved state is a toast, and a dialog that needs a click to dismiss only adds a step.
- Don't discard unsaved input silently when the dialog closes. Ask with an Alert Dialog on top, where Keep editing returns to the form.
- Don't nest dialogs or use one for a long flow. More than four steps belong on a page.

## API reference

### Dialog

| Prop | Type | Default | Description |
|---|---|---|---|
| actionsRef | React.RefObject<DialogRoot.Actions \| null> |  | A ref to imperative actions. - `unmount`: Manually unmounts the dialog. Call this after any externally controlled closing animation finishes. - `close`: Closes the dialog imperatively when called. |
| children | React.ReactNode \| PayloadChildRenderFunction<Payload> |  | The content of the dialog. This can be a regular React node or a render function that receives the `payload` of the active trigger. |
| defaultOpen | boolean | false | Whether the dialog is initially open. To render a controlled dialog, use the `open` prop instead. |
| defaultTriggerId | string \| null |  | ID of the trigger that the dialog is associated with. This is useful in conjunction with the `defaultOpen` prop to create an initially open dialog. |
| disablePointerDismissal | boolean | false | Whether to prevent the dialog from closing on outside presses. For non-modal dialogs, this also prevents the dialog from closing when focus moves outside of it. |
| handle | DialogHandle<Payload> |  | A handle to associate the dialog with a trigger. If specified, allows external triggers to control the dialog's open state. Can be created with the Dialog.createHandle() method. |
| modal | boolean \| 'trap-focus' | true | Determines if the dialog enters a modal state when open. - `true`: user interaction is limited to just the dialog: focus is trapped, document page scroll is locked, and pointer interactions on outside elements are disabled. - `false`: user… |
| onOpenChange | ((open: boolean, eventDetails: DialogRoot.ChangeEventDetails) => void) |  | Event handler called when the dialog is opened or closed. |
| onOpenChangeComplete | ((open: boolean) => void) |  | Event handler called after any animations complete when the dialog is opened or closed. |
| open | boolean |  | Whether the dialog is currently open. |
| triggerId | string \| null |  | ID of the trigger that the dialog is associated with. This is useful in conjunction with the `open` prop to create a controlled dialog. There's no need to specify this prop when the dialog is uncontrolled (that is, when the `open` prop is… |

### DialogBody

| Prop | Type | Default | Description |
|---|---|---|---|
| scrollable | boolean | false | Figma Scrollable body: title and footer stay fixed, the body scrolls. With aria-label or aria-labelledby the scrolling body is announced as a region. |

Also accepts React.HTMLAttributes attributes.

### DialogClose

| Prop | Type | Default | Description |
|---|---|---|---|
| className | string \| ((state: State) => string \| undefined) |  | CSS class applied to the element, or a function that returns a class based on the component's state. |
| nativeButton | boolean | true | Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`). |
| render | React.ReactElement \| ComponentRenderFn<RenderFunctionProps, State> |  | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
| style | React.CSSProperties \| ((state: State) => React.CSSProperties \| undefined) |  | Style applied to the element, or a function that returns a style object based on the component's state. |

Also accepts React.ButtonHTMLAttributes attributes.

### DialogContent

| Prop | Type | Default | Description |
|---|---|---|---|
| appearance | "surface" \| "plain" | "surface" | Figma look (default) or the earlier plain look. |
| className | string \| ((state: State) => string \| undefined) |  | CSS class applied to the element, or a function that returns a class based on the component's state. |
| finalFocus | boolean \| React.RefObject<HTMLElement \| null> \| ((closeType: InteractionType) => boolean \| HTMLElement \| null \| void) |  | Determines the element to focus when the dialog is closed. - `false`: Do not move focus. - `true`: Move focus based on the default behavior (trigger or previously focused element). - `RefObject`: Move focus to the ref element. - `function`… |
| initialFocus | boolean \| React.RefObject<HTMLElement \| null> \| ((openType: InteractionType) => boolean \| HTMLElement \| null \| void) |  | Determines the element to focus when the dialog is opened. By default, focus moves to the first tabbable element inside the popup, except when the dialog is opened by touch — then the popup itself is focused to avoid opening the virtual ke… |
| overlayClassName | string |  | Restyle the backdrop, e.g. a flat page colour for a screen that is only the modal. |
| placement | "center" \| "bottom-right" | "center" | Figma dialog placement: center or bottom-right (help panels). |
| render | React.ReactElement \| ComponentRenderFn<RenderFunctionProps, State> |  | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
| showCloseButton | boolean | true | Shows the close button in the top right corner. Turn it off only when the footer offers a clear way out. |
| showOverlay | boolean | true | Non-modal dialog: omit the backdrop. |
| size | "sm" \| "md" \| "lg" | "sm" | Figma Dialog / Surface Size: Small 384, Medium 512, Large 720. |
| style | React.CSSProperties \| ((state: State) => React.CSSProperties \| undefined) |  | Style applied to the element, or a function that returns a style object based on the component's state. |

Also accepts React.HTMLAttributes attributes.

### DialogDescription

| Prop | Type | Default | Description |
|---|---|---|---|
| className | string \| ((state: State) => string \| undefined) |  | CSS class applied to the element, or a function that returns a class based on the component's state. |
| render | React.ReactElement \| ComponentRenderFn<RenderFunctionProps, State> |  | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
| style | React.CSSProperties \| ((state: State) => React.CSSProperties \| undefined) |  | Style applied to the element, or a function that returns a style object based on the component's state. |

Also accepts React.HTMLAttributes attributes.

### DialogFooter

| Prop | Type | Default | Description |
|---|---|---|---|
| band | boolean |  | Figma "Band": `true` paints the footer fill; omitted = band inside surface dialogs. |
| layout | "inline" \| "stacked" |  | Figma Footer Layout: `inline` one row, `stacked` one column with the primary on top. |
| showCloseButton | boolean | false | Adds a plain Close button to the footer, after your own buttons. |
| start | React.ReactNode |  | Figma Footer Layout "Split": action at the left edge (Back, Compare). |

Also accepts React.HTMLAttributes attributes.

### DialogHeader

| Prop | Type | Default |
|---|---|---|


Also accepts React.HTMLAttributes attributes.

### DialogIcon

| Prop | Type | Default | Description |
|---|---|---|---|
| variant | "warning" \| "default" \| "destructive" | "default" | The look of the round icon: `default` (neutral), `warning` (yellow tint) or `destructive` (red tint). |

Also accepts React.HTMLAttributes attributes.

### DialogOverlay

| Prop | Type | Default | Description |
|---|---|---|---|
| className | string \| ((state: State) => string \| undefined) |  | CSS class applied to the element, or a function that returns a class based on the component's state. |
| forceRender | boolean | false | Whether the backdrop is forced to render even when nested. |
| render | React.ReactElement \| ComponentRenderFn<RenderFunctionProps, State> |  | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
| style | React.CSSProperties \| ((state: State) => React.CSSProperties \| undefined) |  | Style applied to the element, or a function that returns a style object based on the component's state. |

Also accepts React.HTMLAttributes attributes.

### DialogPortal

| Prop | Type | Default | Description |
|---|---|---|---|
| className | string \| ((state: State) => string \| undefined) |  | CSS class applied to the element, or a function that returns a class based on the component's state. |
| container | HTMLElement \| ShadowRoot \| React.RefObject<HTMLElement \| ShadowRoot \| null> \| null |  | A parent element to render the portal element into. |
| keepMounted | boolean | false | Whether to keep the portal mounted in the DOM while the popup is hidden. |
| render | React.ReactElement \| ComponentRenderFn<RenderFunctionProps, State> |  | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
| style | React.CSSProperties \| ((state: State) => React.CSSProperties \| undefined) |  | Style applied to the element, or a function that returns a style object based on the component's state. |

Also accepts React.HTMLAttributes attributes.

### DialogProgress

| Prop | Type | Default | Description |
|---|---|---|---|
| step* | number |  | The current step, from 1. It is clamped to the range of `steps`. |
| steps* | number |  | The number of steps in the flow. Keep it between two and four. |
| label | React.ReactNode |  | A short name for the current step, shown at the right of the Step n of m line. |

Also accepts React.HTMLAttributes attributes.

### DialogSurface

| Prop | Type | Default | Description |
|---|---|---|---|
| appearance | "surface" \| "plain" | "surface" | Figma look (default) or the earlier plain look. |
| onClose | () => void |  | Called when the corner close button is pressed (the static panel has no open state of its own). |
| showCloseButton | boolean | true |  |
| size | "sm" \| "md" \| "lg" | "sm" | Figma Dialog / Surface Size: Small 384, Medium 512, Large 720. |

Also accepts React.HTMLAttributes attributes.

### DialogTitle

| Prop | Type | Default | Description |
|---|---|---|---|
| className | string \| ((state: State) => string \| undefined) |  | CSS class applied to the element, or a function that returns a class based on the component's state. |
| render | React.ReactElement \| ComponentRenderFn<RenderFunctionProps, State> |  | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
| style | React.CSSProperties \| ((state: State) => React.CSSProperties \| undefined) |  | Style applied to the element, or a function that returns a style object based on the component's state. |

Also accepts React.HTMLAttributes attributes.

### DialogTrigger

| Prop | Type | Default | Description |
|---|---|---|---|
| className | string \| ((state: State) => string \| undefined) |  | CSS class applied to the element, or a function that returns a class based on the component's state. |
| handle | DialogHandle<Payload> |  | A handle to associate the trigger with a dialog. Can be created with the Dialog.createHandle() method. |
| id | string |  | ID of the trigger. In addition to being forwarded to the rendered element, it is also used to specify the active trigger for the dialog in controlled mode (with the DialogRoot `triggerId` prop). |
| nativeButton | boolean | true | Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`). |
| payload | Payload |  | A payload to pass to the dialog when it is opened. |
| render | React.ReactElement \| ComponentRenderFn<RenderFunctionProps, State> |  | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
| style | React.CSSProperties \| ((state: State) => React.CSSProperties \| undefined) |  | Style applied to the element, or a function that returns a style object based on the component's state. |

Also accepts React.ButtonHTMLAttributes attributes.

## Examples

### Header: title, description, icon and warning icon, with and without the close button

```tsx
import {
  Dialog,
  DialogClose,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogIcon,
  DialogTitle,
  DialogTrigger,
} from "@/components/ui/dialog"
import { Button } from "@/components/ui/button"
import { CreditCard } from "lucide-react"

export function Example() {
  return (
    <Dialog>
      <DialogTrigger render={<Button variant="plain" />}>Change plan</DialogTrigger>
      <DialogContent>
        <DialogHeader>
          <DialogIcon><CreditCard /></DialogIcon>
          <DialogTitle>Switch to annual billing</DialogTitle>
          <DialogDescription>You save 20 % and are charged $950 today.</DialogDescription>
        </DialogHeader>
        <DialogFooter>
          <DialogClose render={<Button variant="plain" />}>Cancel</DialogClose>
          <Button>Switch plan</Button>
        </DialogFooter>
      </DialogContent>
    </Dialog>
  )
}
```

### Footer: pair, single, split and stacked

```tsx
import {
  Dialog,
  DialogBody,
  DialogClose,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@/components/ui/dialog"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"

export function Example() {
  return (
    <Dialog>
      <DialogTrigger render={<Button variant="plain" />}>Edit details</DialogTrigger>
      <DialogContent>
        <DialogHeader>
          <DialogTitle>Edit details</DialogTitle>
          <DialogDescription>Update the name that appears on invoices.</DialogDescription>
        </DialogHeader>
        <DialogBody>
          <div className="flex flex-col gap-2">
            <Label htmlFor="company">Company name</Label>
            <Input id="company" defaultValue="WunderUI" />
          </div>
        </DialogBody>
        <DialogFooter>
          <DialogClose render={<Button variant="plain" />}>Cancel</DialogClose>
          <Button>Save</Button>
        </DialogFooter>
      </DialogContent>
    </Dialog>
  )
}
```

### Content: text, form, selection, details and long content

```tsx
import {
  Dialog,
  DialogBody,
  DialogClose,
  DialogContent,
  DialogFooter,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@/components/ui/dialog"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"

export function Example() {
  return (
    <Dialog>
      <DialogTrigger render={<Button variant="plain" />}>New project</DialogTrigger>
      <DialogContent size="md">
        <DialogHeader>
          <DialogTitle>Create project</DialogTitle>
        </DialogHeader>
        <DialogBody>
          <div className="flex flex-col gap-2">
            <Label htmlFor="project-name">Project name</Label>
            <Input id="project-name" defaultValue="Northstar" />
          </div>
          <div className="flex flex-col gap-2">
            <Label htmlFor="billing-email">Billing email</Label>
            <Input id="billing-email" type="email" defaultValue="info@wunderui.com" />
          </div>
        </DialogBody>
        <DialogFooter>
          <DialogClose render={<Button variant="plain" />}>Cancel</DialogClose>
          <Button>Create project</Button>
        </DialogFooter>
      </DialogContent>
    </Dialog>
  )
}
```

### Steps: a short multi-step dialog with progress

```tsx
import {
  Dialog,
  DialogBody,
  DialogClose,
  DialogContent,
  DialogFooter,
  DialogHeader,
  DialogProgress,
  DialogTitle,
  DialogTrigger,
} from "@/components/ui/dialog"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"

export function Example() {
  return (
    <Dialog>
      <DialogTrigger render={<Button variant="plain" />}>New workspace</DialogTrigger>
      <DialogContent size="md">
        <DialogHeader>
          <DialogProgress step={1} steps={3} label="Workspace" />
          <DialogTitle>Create a workspace</DialogTitle>
        </DialogHeader>
        <DialogBody>
          <div className="flex flex-col gap-2">
            <Label htmlFor="workspace-name">Workspace name</Label>
            <Input id="workspace-name" defaultValue="WunderUI" />
          </div>
        </DialogBody>
        <DialogFooter>
          <DialogClose render={<Button variant="plain" />}>Cancel</DialogClose>
          <Button>Next</Button>
        </DialogFooter>
      </DialogContent>
    </Dialog>
  )
}
```

### Presentation: modal and non-modal

```tsx
import {
  Dialog,
  DialogBody,
  DialogClose,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@/components/ui/dialog"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"

export function Example() {
  return (
    <Dialog>
      <DialogTrigger render={<Button variant="plain" />}>Invite teammate</DialogTrigger>
      <DialogContent>
        <DialogHeader>
          <DialogTitle>Invite a teammate</DialogTitle>
          <DialogDescription>They get an email with a link to join WunderUI.</DialogDescription>
        </DialogHeader>
        <DialogBody>
          <div className="flex flex-col gap-2">
            <Label htmlFor="invite-email">Email address</Label>
            <Input id="invite-email" type="email" placeholder="name@wunderui.com" />
          </div>
        </DialogBody>
        <DialogFooter>
          <DialogClose render={<Button variant="plain" />}>Cancel</DialogClose>
          <Button>Send invite</Button>
        </DialogFooter>
      </DialogContent>
    </Dialog>
  )
}
```

### States: ready, submitting and failed

```tsx
import {
  Dialog,
  DialogBody,
  DialogClose,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@/components/ui/dialog"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"

export function Example() {
  return (
    <Dialog>
      <DialogTrigger render={<Button variant="plain" />}>Invite teammate</DialogTrigger>
      <DialogContent>
        <DialogHeader>
          <DialogTitle>Invite a teammate</DialogTitle>
          <DialogDescription>They get an email with a link to join WunderUI.</DialogDescription>
        </DialogHeader>
        <DialogBody>
          <div className="flex flex-col gap-2">
            <Label htmlFor="invite-email">Email address</Label>
            <Input id="invite-email" type="email" defaultValue="name@wunderui.com" />
          </div>
        </DialogBody>
        <DialogFooter>
          <DialogClose render={<Button variant="plain" />}>Cancel</DialogClose>
          <Button>Send invite</Button>
        </DialogFooter>
      </DialogContent>
    </Dialog>
  )
}
```

### Content state: loading, empty and error

```tsx
import {
  Dialog,
  DialogBody,
  DialogClose,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@/components/ui/dialog"
import { Button } from "@/components/ui/button"
import { Skeleton } from "@/components/ui/skeleton"

export function Example() {
  return (
    <Dialog>
      <DialogTrigger render={<Button variant="plain" />}>Add members</DialogTrigger>
      <DialogContent>
        <DialogHeader>
          <DialogTitle>Add members</DialogTitle>
          <DialogDescription>Choose from people in your organisation.</DialogDescription>
        </DialogHeader>
        <DialogBody>
          <div className="flex flex-col gap-3" role="status" aria-busy="true">
            <div className="flex items-center gap-3">
              <Skeleton variant="avatar" />
              <Skeleton variant="text" className="w-40" />
            </div>
            <div className="flex items-center gap-3">
              <Skeleton variant="avatar" />
              <Skeleton variant="text" className="w-32" />
            </div>
            <div className="flex items-center gap-3">
              <Skeleton variant="avatar" />
              <Skeleton variant="text" className="w-36" />
            </div>
          </div>
        </DialogBody>
        <DialogFooter>
          <DialogClose render={<Button variant="plain" />}>Cancel</DialogClose>
          <Button disabled>Add members</Button>
        </DialogFooter>
      </DialogContent>
    </Dialog>
  )
}
```

## In context

### Create project: a form that validates and submits

An empty name is flagged on the field and the dialog stays open. While the request runs, the primary shows its pending state and Cancel is disabled, and the dialog closes when done.

```tsx
import { useState } from "react"
import {
  Dialog,
  DialogBody,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@/components/ui/dialog"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"

export function CreateProject() {
  const [open, setOpen] = useState(false)
  const [name, setName] = useState("")
  const [error, setError] = useState(false)
  const [pending, setPending] = useState(false)

  const submit = () => {
    if (name.trim() === "") {
      setError(true)
      return
    }
    setPending(true)
    // Stand-in for a request: close the dialog once the server confirmed.
    window.setTimeout(() => {
      setPending(false)
      setOpen(false)
      setName("")
    }, 1200)
  }

  return (
    <Dialog open={open} onOpenChange={setOpen}>
      <DialogTrigger render={<Button variant="plain" />}>New project</DialogTrigger>
      <DialogContent size="md">
        <DialogHeader>
          <DialogTitle>Create project</DialogTitle>
          <DialogDescription>Projects hold tasks, files and members.</DialogDescription>
        </DialogHeader>
        <DialogBody>
          <div className="flex flex-col gap-2">
            <Label htmlFor="project-name">Project name</Label>
            <Input
              id="project-name"
              value={name}
              aria-invalid={error || undefined}
              aria-describedby={error ? "project-name-error" : undefined}
              onChange={(event) => {
                setName(event.target.value)
                setError(false)
              }}
            />
            {error && <p id="project-name-error" role="alert" className="text-xs text-error">Enter a project name.</p>}
          </div>
        </DialogBody>
        <DialogFooter>
          <Button variant="plain" disabled={pending} onClick={() => setOpen(false)}>Cancel</Button>
          <Button pending={pending} onClick={submit}>{pending ? "Creating…" : "Create project"}</Button>
        </DialogFooter>
      </DialogContent>
    </Dialog>
  )
}
```

### Assign a task: choose one person from a list

A single choice from a short list, with the name of the choice repeated on the primary action.

```tsx
import { useState } from "react"
import {
  Dialog,
  DialogBody,
  DialogClose,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@/components/ui/dialog"
import { Avatar, AvatarFallback } from "@/components/ui/avatar"
import { Button } from "@/components/ui/button"
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
import { SelectorItem, SelectorItemGroup } from "@/components/ui/selector-item"

export function AssignTask() {
  const [assignee, setAssignee] = useState("Nora Lindgren")

  return (
    <Dialog>
      <DialogTrigger render={<Button variant="plain" />}>Assign task</DialogTrigger>
      <DialogContent size="md">
        <DialogHeader>
          <DialogTitle>Assign task</DialogTitle>
          <DialogDescription>Pick who is responsible for Update onboarding flow.</DialogDescription>
        </DialogHeader>
        <DialogBody>
          <RadioGroup aria-label="People" value={assignee} onValueChange={setAssignee}>
            <SelectorItemGroup>
              <SelectorItem
                controlPosition="leading"
                control={<RadioGroupItem value="Nora Lindgren" tone="tint" />}
                leading={<Avatar color="purple"><AvatarFallback>NL</AvatarFallback></Avatar>}
                title="Nora Lindgren"
                description="Product designer"
              />
              <SelectorItem
                controlPosition="leading"
                control={<RadioGroupItem value="Daniel Okafor" tone="tint" />}
                leading={<Avatar color="green"><AvatarFallback>DO</AvatarFallback></Avatar>}
                title="Daniel Okafor"
                description="Engineering lead"
              />
              <SelectorItem
                controlPosition="leading"
                control={<RadioGroupItem value="Priya Raman" tone="tint" />}
                leading={<Avatar color="indigo"><AvatarFallback>PR</AvatarFallback></Avatar>}
                title="Priya Raman"
                description="Marketing"
              />
            </SelectorItemGroup>
          </RadioGroup>
        </DialogBody>
        <DialogFooter>
          <DialogClose render={<Button variant="plain" />}>Cancel</DialogClose>
          <DialogClose render={<Button />}>Assign to {assignee.split(" ")[0]}</DialogClose>
        </DialogFooter>
      </DialogContent>
    </Dialog>
  )
}
```

### Create a workspace: three steps with progress

Next moves on and Back goes one step back. The last step reviews what will be created.

```tsx
import { useState } from "react"
import {
  Dialog,
  DialogBody,
  DialogContent,
  DialogFooter,
  DialogHeader,
  DialogProgress,
  DialogTitle,
  DialogTrigger,
} from "@/components/ui/dialog"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"

export function CreateWorkspace() {
  const [open, setOpen] = useState(false)
  const [step, setStep] = useState(1)

  const close = (next: boolean) => {
    setOpen(next)
    if (!next) setStep(1)
  }

  return (
    <Dialog open={open} onOpenChange={close}>
      <DialogTrigger render={<Button variant="plain" />}>New workspace</DialogTrigger>
      <DialogContent size="md">
        <DialogHeader>
          <DialogProgress step={step} steps={3} label={["Workspace", "Team", "Review"][step - 1]} />
          <DialogTitle>Create a workspace</DialogTitle>
        </DialogHeader>
        <DialogBody>
          {step === 1 && (
            <div className="flex flex-col gap-2">
              <Label htmlFor="workspace-name">Workspace name</Label>
              <Input id="workspace-name" defaultValue="WunderUI" />
            </div>
          )}
          {step === 2 && (
            <div className="flex flex-col gap-2">
              <Label htmlFor="teammate">Invite a teammate</Label>
              <Input id="teammate" type="email" placeholder="name@wunderui.com" />
            </div>
          )}
          {step === 3 && (
            <p className="text-sm text-text-secondary">WunderUI is created in Europe with one pending invite.</p>
          )}
        </DialogBody>
        <DialogFooter start={step > 1 ? <Button variant="plain" onClick={() => setStep(step - 1)}>Back</Button> : undefined}>
          {step === 1 && <Button variant="plain" onClick={() => close(false)}>Cancel</Button>}
          {step < 3 ? <Button onClick={() => setStep(step + 1)}>Next</Button> : <Button onClick={() => close(false)}>Create workspace</Button>}
        </DialogFooter>
      </DialogContent>
    </Dialog>
  )
}
```

## For AI agents

`get_component("dialog")`

Hand your agent this page as Markdown or the WunderUI MCP server, not a screenshot.
