> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Dialog

Show content in a centered panel over a dimmed backdrop. Tapping the backdrop closes it.


## Installation

```bash
npx @blotch/dolan add dialog
```

```typescript
import {
  UiDialog,
  UiDialogHeader,
  UiDialogTitle,
  UiDialogDescription,
  UiDialogFooter,
} from '../components/ui/dialog';
```

## Usage

```typescript
import { Component, signal } from '@angular/core';
import {
  UiDialog,
  UiDialogHeader,
  UiDialogTitle,
  UiDialogDescription,
  UiDialogFooter,
} from '../components/ui/dialog';
import { UiButton } from '../components/ui/button';

@Component({
  selector: 'app-edit-profile',
  imports: [
    UiDialog,
    UiDialogHeader,
    UiDialogTitle,
    UiDialogDescription,
    UiDialogFooter,
    UiButton,
  ],
  template: `
    <ui-button (pressed)="open.set(true)">Edit profile</ui-button>

    <ui-dialog [(open)]="open">
      <ui-dialog-header>
        <ui-dialog-title>Edit profile</ui-dialog-title>
        <ui-dialog-description>
          Make changes to your profile here.
        </ui-dialog-description>
      </ui-dialog-header>
      <ui-dialog-footer>
        <ui-button variant="outline" (pressed)="open.set(false)">
          Cancel
        </ui-button>
        <ui-button (pressed)="open.set(false)">Save</ui-button>
      </ui-dialog-footer>
    </ui-dialog>
  `,
})
export class EditProfile {
  protected readonly open = signal(false);
}
```

- `[(open)]` two-way binds a signal. Set it to `true` to open the dialog and `false` to close it.
- A backdrop tap, or Android's back button, sets `open` back to `false`. Taps inside the panel don't reach the backdrop.
- The backdrop fades in and the panel scales up. Closing plays the reverse.
- The dialog draws in an [`<overlay>`](/api/elements/overlay.md), so it covers the whole screen wherever it sits in your template.
- When it opens, a screen reader moves into the panel and stays inside it until the dialog closes.
- `<ui-dialog-title>` and `<ui-dialog-description>` render `<text>`, so put plain text in them. The footer lays out its buttons in a row, aligned right.

### Run code after it closes

`closed` emits once the close animation has finished, about 270ms after `open` turns `false`. It fires from a timer, outside any tap handler, so it's a safe place to navigate.

```typescript
// <ui-dialog [(open)]="open" (closed)="onClosed()">
readonly #router = inject(Router);

protected onClosed(): void {
  this.#router.navigateByUrl('/profile');
}
```

You can also navigate straight from a button in the dialog, as from any tap handler.

### Other content

Put any elements between the header and footer, such as a form. Import `LYNX_ELEMENTS` in your component for them.

```angular-html
<ui-dialog [(open)]="open">
  <ui-dialog-header>
    <ui-dialog-title>Rename</ui-dialog-title>
  </ui-dialog-header>
  <view class="py-4">
    <text class="text-sm text-foreground">Name: John Doe</text>
  </view>
</ui-dialog>
```

### Panel width

`class` goes on the panel, which is `w-4/5` wide by default.

```angular-html
<ui-dialog [(open)]="open" class="w-11/12">…</ui-dialog>
```

### Make the user choose

A backdrop tap or Android's back button lets the user leave without choosing. When they must pick an action, such as confirming a delete, use [Alert Dialog](/dolan/alert-dialog.md) with `[cancelable]="false"` instead: by default, Android's back button cancels an alert dialog too.

## API

### UiDialog

| Input   | Type      | Default | Description                                       |
| ------- | --------- | ------- | ------------------------------------------------- |
| `open`  | `boolean` | `false` | Whether the dialog is shown. Supports `[(open)]`. |
| `class` | `string`  | `''`    | Extra Tailwind classes for the panel.             |

| Output       | Type      | Description                                                                                       |
| ------------ | --------- | ------------------------------------------------------------------------------------------------- |
| `openChange` | `boolean` | Emits `false` when a backdrop tap or Android's back button closes the dialog. Part of `[(open)]`. |
| `closed`     | `void`    | Emits after the close animation finishes.                                                         |

All sub-components (`UiDialogHeader`, `UiDialogTitle`, `UiDialogDescription`, `UiDialogFooter`) accept `class`.

## Related

- [Dialogs and overlays](/guide/overlays.md): how overlays work and which one to use
- [Alert Dialog](/dolan/alert-dialog.md): a dialog the backdrop can't close
- [Sheet](/dolan/sheet.md): a panel from the bottom of the screen
- [`<overlay>`](/api/elements/overlay.md): the element the dialog draws in
