Dialog
Modal dialog with focus trap, Escape-to-close and focus restoration.
Preview
Edit profile
Make changes to your profile here. Click save when you're done.
Controls
Device view renders in an isolated frame so real responsive breakpoints apply. Switch to Full for overflowing popovers.
Installation
php artisan ui:add dialog
Behavior layer (Alpine)
This component installs a self-registering Alpine module to
resources/js/ui/dialog.js. Import the behavior layer once
from your bundle so it loads (it hooks alpine:init):
import './dialog.js';
Registry contract
Install confidence
php artisan ui:add dialog
writes only the generated targets below. The CLI validates each file hash before writing and
prompts before replacing local changes unless --force is used.
- Version
- 1.2.0
- License
- open
- Stability
- stable
- Contract
- v2
- Foundation
- ≥ 1.0.0
| Type | Generated target |
|---|---|
| blade | resources/views/components/ui/dialog.blade.php |
| blade | resources/views/components/ui/dialog/trigger.blade.php |
| blade | resources/views/components/ui/dialog/content.blade.php |
| blade | resources/views/components/ui/dialog/header.blade.php |
| blade | resources/views/components/ui/dialog/title.blade.php |
| blade | resources/views/components/ui/dialog/description.blade.php |
| blade | resources/views/components/ui/dialog/footer.blade.php |
| blade | resources/views/components/ui/dialog/close.blade.php |
| js | resources/js/ui/dialog.js |
Registry dependencies
None.
Package dependencies
composer: jml/brok:^1.0
npm: alpinejs
Guidance
Focused overlayHandle a short focused interruption or blocking decision.
Use when
- Use for short, self-contained work that benefits from preserving page context, or for interruptions that truly deserve focused attention. Do not use for long forms, multi-step tasks, or broad comparison work that needs more room and less interruption.
- The user must complete or acknowledge a focused task before returning to the page.
- Confirming a consequential action or editing a compact form.
Avoid when
- Reserve for confirmations, critical warnings, or short blocking decisions that genuinely require focused attention.
- The content is non-modal contextual help; use popover.
- The task benefits from persistent edge-aligned space; use sheet.
- The workflow is a mobile-first drag-dismiss surface; use drawer.
- Task length
- short
- Interaction cost
- high
- Interruptiveness
- high
- Input precision
- none
- Mobile / touch risk
- high
- Accessibility risk
- high
- Needs background context
- Yes
- Comparison needed
- No
Preferred alternatives
- Inline content
- Drawer or dedicated page for longer tasks
Anti-patterns
- Long forms in dialogs
- Multi-step or comparison-heavy modal workflows
Anatomy
root
trigger
overlay
content
header
title
description
footer
close
Theming hooks
dialog overlay
dialog content
dialog close
Canonical examples
defaultsizesscrollablewith-formfullscreen
API
manifest knowledge + registry-derived coverageProps
| Prop | Type / values | Default | Description |
|---|---|---|---|
| open | bool | false | Initial open state. |
| size | sm|md|lg|xl|full | md | Maximum content width or fullscreen presentation. |
| scrollable | bool | false | Declared by @props in the registry Blade source. |
| sticky | bool | false | Declared by @props in the registry Blade source. |
Slots
default— Compose trigger, content, header, title, description, footer, and close subcomponents.x-ui.dialog.trigger— Installed subcomponent from the registry item.x-ui.dialog.content— Installed subcomponent from the registry item.x-ui.dialog.header— Installed subcomponent from the registry item.x-ui.dialog.title— Installed subcomponent from the registry item.x-ui.dialog.description— Installed subcomponent from the registry item.x-ui.dialog.footer— Installed subcomponent from the registry item.x-ui.dialog.close— Installed subcomponent from the registry item.
Data slots
dialog
dialog-close
dialog-content
dialog-description
dialog-footer
dialog-header
dialog-overlay
dialog-portal
dialog-title
dialog-trigger
Capabilities
Behavior
- Traps focus while open, closes on Escape, and restores focus to the trigger.
- Teleports the overlay so ancestor overflow does not clip the modal.
- Traps focus while open, closes on Escape/overlay click, locks body scroll, and restores focus to the trigger.
- Installs a JavaScript behavior module when the registry item includes resources/js/ui files.
- Declares registry capability flags: a11y, interactive, responsive, rtl, darkMode, localized.
Usage
<x-ui.dialog>
<x-ui.dialog.trigger class="inline-flex h-10 items-center justify-center rounded-md bg-primary px-4 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background">
{{ __('Edit profile') }}
</x-ui.dialog.trigger>
<x-ui.dialog.content>
<x-ui.dialog.close />
<x-ui.dialog.header>
<x-ui.dialog.title>{{ __('Edit profile') }}</x-ui.dialog.title>
<x-ui.dialog.description>{{ __("Make changes to your profile here. Click save when you're done.") }}</x-ui.dialog.description>
</x-ui.dialog.header>
<div class="mt-4 space-y-2">
<x-ui.label for="name">{{ __('Name') }}</x-ui.label>
<x-ui.input id="name" value="Ada Lovelace" />
</div>
<x-ui.dialog.footer>
<button type="button" @click="hide()" class="inline-flex h-10 items-center justify-center rounded-md border border-border bg-background px-4 text-sm font-medium text-foreground transition-colors hover:bg-muted">
{{ __('Cancel') }}
</button>
<button type="button" @click="hide()" class="inline-flex h-10 items-center justify-center rounded-md bg-primary px-4 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90">
{{ __('Save changes') }}
</button>
</x-ui.dialog.footer>
</x-ui.dialog.content>
</x-ui.dialog>
Accessibility & localization
data-slot
Keyboard focus-visible
Localized labels
- Always provide a dialog title; add a description when the purpose is not obvious.
- Keep the primary action last in logical focus order.
- Uses semantic HTML and a stable
data-slotattribute for styling/scripting hooks. - Focus-visible rings use the
ringtoken so keyboard focus is always visible. - Disabled and invalid states are conveyed to assistive tech, not by color alone.
- Targets WCAG 2.2 AA; verify contrast in light, dark, admin and customer surfaces above.
- Labels go through
__()and the component uses logical properties (ms-*,text-start,start-*) so it mirrors correctly — flip the preview to RTL to confirm.
Source
The exact, editable file ui:add writes
into your app — copy it or own the whole thing. Previews
render this same code; there are no preview-only components.
Changelog
Current version: v1.2.0. See the site changelog for the full release history.