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

NameTypeDefaultDescription
openBooleanfalseWhether the element is open
close_on_escapeBooleantrueThe close on escape

Action

Primary action button for the alert dialog.

Parameters

NameTypeDefaultDescription
variantSymbol:defaultVisual style variant
sizeSymbol:defaultSize of the element

Cancel

Cancel button for the alert dialog.

Parameters

NameTypeDefaultDescription
variantSymbol:outlineVisual style variant
sizeSymbol:defaultSize 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

NameTypeDefaultDescription
openBooleanfalseWhether 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

KeyDescription
EscapeCloses the component

JavaScript

Stimulus Controller

ui--alert-dialog

Values

NameTypeDescription
openBooleanControls open state

Actions

opencloseshowhidepreventOverlayClose

Events

EventDescriptionDetail
alertdialog:openFired when alertdialog open-
alertdialog:closeFired when alertdialog close-