# Dialog

- **Section:** Components
- **URL:** https://refast.fastapicloud.dev/docs/components/dialog
- **Markdown:** https://refast.fastapicloud.dev/docs/components/dialog.md
- **Source:** https://github.com/idling-mind/refast-docs/blob/main/docs/pages/components/feedback/dialog.py
- **Live examples:** the widgets on this page need a browser; open the URL above to try them.
- **Applies to:** refast 0.12.2

A modal dialog that interrupts the user with important content and
expects a response. Use `variant="destructive"` for confirmation
of dangerous actions.

```python
from refast.components import (
    Dialog, DialogTrigger, DialogContent, DialogHeader,
    DialogTitle, DialogDescription, DialogFooter, DialogAction, DialogCancel,
)
```

Use a destructive variant dialog to confirm dangerous actions.

## Props

### `Dialog`

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `open` | `bool \| None` | `None` | Controlled open state |
| `default_open` | `bool` | `False` | Initial open state |
| `on_open_change` | `Callback \| None` | `None` | Called when open state changes |
| `backdrop` | `bool` | `True` | Whether to render the semi-transparent overlay backdrop |
| `modal` | `bool \| None` | `None` | Enables modal interaction mode (traps focus, disables body scroll) |
| `title` | `str \| None` | `None` | Shorthand title (skips `DialogHeader`) |
| `description` | `str \| None` | `None` | Shorthand description |
| `confirm_label` | `str` | `"Continue"` | Label for the confirm button |
| `cancel_label` | `str` | `"Cancel"` | Label for the cancel button |
| `on_confirm` | `Callback \| None` | `None` | Confirm callback |
| `on_cancel` | `Callback \| None` | `None` | Cancel callback |
| `variant` | `"default" \| "destructive"` | `"default"` | Visual style |
| `trigger` | `Component \| None` | `None` | Shorthand trigger component |
| `width` | `str \| None` | `None` | Custom width (e.g., `"500px"`, `"90vw"`) |
| `height` | `str \| None` | `None` | Custom height (e.g., `"400px"`, `"80vh"`) |
| `max_width` | `str \| None` | `None` | Custom max-width limit (e.g., `"1000px"`) |
| `max_height` | `str \| None` | `None` | Custom max-height limit |

### `DialogContent`

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `width` | `str \| None` | `None` | Custom width (e.g., `"500px"`, `"90vw"`) |
| `height` | `str \| None` | `None` | Custom height (e.g., `"400px"`, `"80vh"`) |
| `max_width` | `str \| None` | `None` | Custom max-width limit (e.g., `"1000px"`) |
| `max_height` | `str \| None` | `None` | Custom max-height limit |

### `DialogAction`

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `label` | `str` | *(required)* | Button text |
| `on_click` | `Callback \| None` | `None` | Click callback |

### `DialogCancel`

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `label` | `str` | `"Cancel"` | Button text |
| `on_click` | `Callback \| None` | `None` | Click callback |

## Shorthand API

For simple dialogs, use the shorthand props on `Dialog` instead of
composing `DialogContent`, `DialogHeader`, etc.:

```python
Dialog(
    trigger=Button("Open"),
    title="Confirm action",
    description="Are you sure you want to proceed?",
    confirm_label="Yes, proceed",
    cancel_label="No, cancel",
    on_confirm=ctx.callback(handle_confirm),
    on_cancel=ctx.callback(handle_cancel),
)
```

## Composable API

For custom content, use the full component hierarchy:

```python
Dialog(
    open=show_dialog,
    on_open_change=ctx.callback(handle_open_change),
    children=[
        DialogTrigger(children=[Button("Open")]),
        DialogContent(
            children=[
                DialogHeader(
                    children=[
                        DialogTitle(title="Edit Profile"),
                        DialogDescription(description="Make changes here."),
                    ]
                ),
                # custom form fields
                DialogFooter(
                    children=[
                        DialogCancel(label="Cancel"),
                        DialogAction(label="Save", on_click=ctx.callback(handle_save)),
                    ]
                ),
            ]
        ),
    ]
)
```

---

Part of the Refast documentation: [all pages](https://refast.fastapicloud.dev/llms.txt), [everything on one page](https://refast.fastapicloud.dev/llms-full.txt), [search](https://refast.fastapicloud.dev/api/search?q=save_prop).
