--- title: "dialog" description: "Modal dialog with focus trap, backdrop, and Esc-to-close." category: "Overlays" --- # dialog Modal dialog with focus trap, backdrop, and Esc-to-close. ## Installation ```bash php artisan ui:add dialog ``` ## Dependencies - composer: `gehrisandro/tailwind-merge-laravel` - component: [button](https://laralcn-ui.abdulkadersafi.com/components/button.md) — the CLI installs it for you. ## Usage ```blade Open dialog

Dialog body content.

Cancel Delete
``` ## Example The demo rendered on the docs page. ```blade Open dialog

This will permanently delete the project and all of its data.

Cancel Delete
``` ## Source Copy this file to the path shown above it. `resources/views/components/ui/dialog.blade.php` ```blade @props([ 'title' => null, 'description' => null, ]) @php // A native dialog element opened with showModal() gives us the top // layer (so no // ancestor transform or backdrop-filter can clip it), a focus trap, Esc to // close and an inert page for free. The script below only handles opening, // the exit animation and the scroll lock. $id = 'ui-dialog-' . bin2hex(random_bytes(4)); // Not bg-black/50. Tailwind v4 compiles that to oklab(0 0 0 / 0.5), and // Chrome does not paint a modern colour function with alpha inside the // dialog top layer, so the scrim silently renders as nothing. A legacy // rgb() with alpha composites correctly in the same place. $overlay = 'absolute inset-0 bg-[rgb(0_0_0/0.5)] opacity-0 transition-opacity duration-200 group-data-[state=open]/dialog:opacity-100'; $panel = \TailwindMerge\Laravel\Facades\TailwindMerge::merge( 'absolute left-1/2 top-1/2 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 scale-95 gap-4 rounded-lg border bg-background p-6 opacity-0 shadow-lg transition-all duration-200 group-data-[state=open]/dialog:scale-100 group-data-[state=open]/dialog:opacity-100 sm:max-w-lg', $attributes->get('class'), ); @endphp
except('class') }}> {{ $trigger }}
@if ($title || $description)
@if ($title)

{{ $title }}

@endif @if ($description)

{{ $description }}

@endif
@endif {{ $slot }} @isset($footer)
{{ $footer }}
@endisset
@once @endonce ``` ## Theme tokens `--background`, `--border`, `--muted-foreground`, `--ring`, `--radius` Built on the native element (top layer, focus trap, Esc to close) plus a small inline