Dialog
A modal dialog that interrupts the user with important content and expects a response. Requires Alpine.js.
Usage
el.getClientRects().length > 0);
if (!nodes.length) { $event.preventDefault(); return; }
const first = nodes[0];
const last = nodes[nodes.length - 1];
if ($event.shiftKey && document.activeElement === first) { $event.preventDefault(); last.focus(); }
else if (!$event.shiftKey && document.activeElement === last) { $event.preventDefault(); first.focus(); }
"
x-transition:enter="transition ease-out duration-200"
x-transition:enter-start="opacity-0 scale-95"
x-transition:enter-end="opacity-100 scale-100"
x-transition:leave="transition ease-in duration-150"
x-transition:leave-start="opacity-100 scale-100"
x-transition:leave-end="opacity-0 scale-95"
@click.stop
class="fixed top-1/2 left-1/2 z-[51] grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-lg border bg-background p-6 shadow-lg outline-none sm:max-w-lg"
>
Edit profile
Make changes to your profile here. Click save when you're done.
Composition
code
Dialog
├── DialogTrigger
└── DialogContent
├── DialogHeader
│ ├── DialogTitle
│ └── DialogDescription
├── …body…
└── DialogFooter
Prefer title / description / footer on dialog-content for typical forms. Compose the parts manually for custom layouts.
Custom composition
el.getClientRects().length > 0);
if (!nodes.length) { $event.preventDefault(); return; }
const first = nodes[0];
const last = nodes[nodes.length - 1];
if ($event.shiftKey && document.activeElement === first) { $event.preventDefault(); last.focus(); }
else if (!$event.shiftKey && document.activeElement === last) { $event.preventDefault(); first.focus(); }
"
x-transition:enter="transition ease-out duration-200"
x-transition:enter-start="opacity-0 scale-95"
x-transition:enter-end="opacity-100 scale-100"
x-transition:leave="transition ease-in duration-150"
x-transition:leave-start="opacity-100 scale-100"
x-transition:leave-end="opacity-0 scale-95"
@click.stop
class="fixed top-1/2 left-1/2 z-[51] grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-lg border bg-background p-6 shadow-lg outline-none sm:max-w-lg"
>
Share link
Anyone with the link can view this document.
Without close button
el.getClientRects().length > 0);
if (!nodes.length) { $event.preventDefault(); return; }
const first = nodes[0];
const last = nodes[nodes.length - 1];
if ($event.shiftKey && document.activeElement === first) { $event.preventDefault(); last.focus(); }
else if (!$event.shiftKey && document.activeElement === last) { $event.preventDefault(); first.focus(); }
"
x-transition:enter="transition ease-out duration-200"
x-transition:enter-start="opacity-0 scale-95"
x-transition:enter-end="opacity-100 scale-100"
x-transition:leave="transition ease-in duration-150"
x-transition:leave-start="opacity-100 scale-100"
x-transition:leave-end="opacity-0 scale-95"
@click.stop
class="fixed top-1/2 left-1/2 z-[51] grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-lg border bg-background p-6 shadow-lg outline-none sm:max-w-lg"
>
Are you sure?
This action cannot be undone.
API Reference
Dialog
| Prop | Type | Default | Description |
|---|---|---|---|
open |
bool |
false |
Initial open state |
as |
string |
div |
Root HTML element |
DialogContent
| Prop | Type | Default | Description |
|---|---|---|---|
showCloseButton |
bool |
true |
Corner close control |
title |
string |
— | Compose dialog-title |
description |
string |
— | Compose dialog-description |
Named slot: footer → wraps content in dialog-footer.
Parts
dialog-trigger, dialog-close, dialog-header, dialog-footer, dialog-title, and dialog-description.
Notes
- Escape closes the dialog; clicking the overlay also closes it
dialog-contentteleports tobodyso stacking context stays correct- Consumers need Alpine.js (Livewire includes it)