Alert Dialog
AlertDialog - Phlex implementation
Examples
Default
A modal dialog that interrupts the user with important content and expects a response.
Are you absolutely sure?
This action cannot be undone. This will permanently delete your account and remove your data from our servers.
<%= render UI::AlertDialog.new(id: "phlex-dialog") do %>
<%= render UI::AlertDialogTrigger.new do %>
<%= render UI::Button.new { "Show Dialog" } %>
<% end %>
<%= render UI::AlertDialogOverlay.new do %>
<%= render UI::AlertDialogContent.new do %>
<%= render UI::AlertDialogHeader.new do %>
<%= render UI::AlertDialogTitle.new { "Are you absolutely sure?" } %>
<%= render UI::AlertDialogDescription.new { "This action cannot be undone. This will permanently delete your account and remove your data from our servers." } %>
<% end %>
<%= render UI::AlertDialogFooter.new do %>
<%= render UI::AlertDialogCancel.new { "Cancel" } %>
<%= render UI::AlertDialogAction.new { "Continue" } %>
<% end %>
<% end %>
<% end %>
<% end %>Destructive
Alert dialog with a destructive action button.
Delete Account
Are you sure you want to delete your account? All of your data will be permanently removed.
<%= render UI::AlertDialog.new(id: "destructive-phlex") do %>
<%= render UI::AlertDialogTrigger.new do %>
<%= render UI::Button.new(variant: :destructive) { "Delete Account" } %>
<% end %>
<%= render UI::AlertDialogOverlay.new do %>
<%= render UI::AlertDialogContent.new do %>
<%= render UI::AlertDialogHeader.new do %>
<%= render UI::AlertDialogTitle.new { "Delete Account" } %>
<%= render UI::AlertDialogDescription.new { "Are you sure you want to delete your account? All of your data will be permanently removed." } %>
<% end %>
<%= render UI::AlertDialogFooter.new do %>
<%= render UI::AlertDialogCancel.new { "Cancel" } %>
<%= render UI::AlertDialogAction.new(variant: :destructive) { "Delete" } %>
<% end %>
<% end %>
<% end %>
<% end %>Features
- Custom styling with Tailwind classes
- Focus management
API Reference
Alert Dialog
A modal alert dialog component for important confirmations and alerts.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| open | Boolean | false | Whether the element is open |
| close_on_escape | Boolean | true | The close on escape |
Action
Primary action button for the alert dialog.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| variant | Symbol | :default | Visual style variant |
| size | Symbol | :default | Size of the element |
Cancel
Cancel button for the alert dialog.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| variant | Symbol | :outline | Visual style variant |
| size | Symbol | :default | Size of the element |
Content
Main alert dialog content area with proper ARIA attributes.
Description
Description text for the alert dialog.
Footer
Footer section with action buttons for the alert dialog.
Header
Header section of the alert dialog.
Overlay
Container wrapper with backdrop and content for the alert dialog overlay.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| open | Boolean | false | Whether the element is open |
Title
Title text for the alert dialog.
Trigger
A wrapper that adds the alert dialog open action to its child element.
Accessibility
Implements the WAI-ARIA Alert Dialog pattern with proper roles, states, and keyboard navigation.
Keyboard Shortcuts
| Key | Description |
|---|---|
| Escape | Closes the component |
JavaScript
Stimulus Controller
ui--alert-dialogValues
| Name | Type | Description |
|---|---|---|
| open | Boolean | Controls open state |
Actions
opencloseshowhidepreventOverlayCloseEvents
| Event | Description | Detail |
|---|---|---|
| alertdialog:open | Fired when alertdialog open | - |
| alertdialog:close | Fired when alertdialog close | - |