Modal confirmation built on the native dialog element. It needs an explicit cancel or action choice and never closes on a backdrop click.
<x-markas.alert-dialog title="Publish this post?">
<x-slot:trigger>
<x-markas.button>Publish post</x-markas.button>
</x-slot:trigger>
Your post will be visible to everyone who follows your blog.
</x-markas.alert-dialog><script lang="ts">
import AlertDialog from "$lib/components/markas/AlertDialog.svelte";
import Button from "$lib/components/markas/Button.svelte";
</script>
<AlertDialog title="Publish this post?">
{#snippet trigger()}
<Button>Publish post</Button>
{/snippet}
Your post will be visible to everyone who follows your blog.
</AlertDialog>---
import AlertDialog from "@/components/markas/AlertDialog.astro";
import Button from "@/components/markas/Button.astro";
---
<AlertDialog title="Publish this post?">
<Button slot="trigger">Publish post</Button>
Your post will be visible to everyone who follows your blog.
</AlertDialog>Examples
Destructive action
<div class="flex justify-center">
<x-markas.alert-dialog title="Delete your account?" variant="danger" action-label="Delete account">
<x-slot:trigger>
<x-markas.button variant="danger">Delete account</x-markas.button>
</x-slot:trigger>
All of your projects, invoices, and team members will be removed. You cannot undo this action.
</x-markas.alert-dialog>
</div>Discard changes
Draft: Q3 product update
3 unsaved changes
Draft: Q3 product update
3 unsaved changes
Draft: Q3 product update
3 unsaved changes
Draft: Q3 product update
3 unsaved changes
Draft: Q3 product update
3 unsaved changes
With icon trigger
<div class="flex justify-center">
<x-markas.alert-dialog title="Sign out of all devices?" action-label="Sign out">
<x-slot:trigger>
<x-markas.button variant="ghost">
<svg class="size-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M15 4h3a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2h-3M10 17l-5-5 5-5M5 12h11" /></svg>
Sign out everywhere
</x-markas.button>
</x-slot:trigger>
You will need to sign in again on your phone, tablet, and other browsers.
</x-markas.alert-dialog>
</div>Installation
npx markasui@latest add alert-dialogpnpm dlx markasui@latest add alert-dialogyarn dlx markasui@latest add alert-dialogbunx --bun markasui@latest add alert-dialog- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Install the dependency:
npm install alpinejs - Copy the component source below to
resources/views/components/markas/alert-dialog.blade.php.
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/AlertDialog.tsx.
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/AlertDialog.vue.
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/lib/components/markas/AlertDialog.svelte.
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/AlertDialog.astro.
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/app/markas/alert-dialog.component.ts.
Usage
<x-markas.alert-dialog title="Delete your account?" variant="danger" action-label="Delete account" x-on:markas-action="deleteAccount()">
<x-slot:trigger>
<x-markas.button variant="danger">Delete account</x-markas.button>
</x-slot:trigger>
All of your projects and invoices will be removed. You cannot undo this action.
</x-markas.alert-dialog>Needs Alpine.js. Livewire 3 and 4 already ship it.
Livewire
<x-markas.alert-dialog title="Delete project?" wire:model="confirming" wire:markas-action="delete">
This cannot be undone.
</x-markas.alert-dialog>wire:model binds the open state. wire:markas-action runs a Livewire action when the action button is pressed; wire:markas-cancel for any other close.
import { AlertDialog } from "@/components/markas/AlertDialog";
import { Button } from "@/components/markas/Button";
<AlertDialog
title="Delete your account?"
variant="danger"
actionLabel="Delete account"
trigger={<Button variant="danger">Delete account</Button>}
onAction={() => deleteAccount()}
onCancel={() => console.log("kept")}
>
All of your projects and invoices will be removed. You cannot undo this
action.
</AlertDialog>;<template>
<AlertDialog
title="Delete your account?"
variant="danger"
action-label="Delete account"
@action="deleteAccount"
>
<template #trigger>
<Button variant="danger">Delete account</Button>
</template>
All of your projects and invoices will be removed. You cannot undo this
action.
</AlertDialog>
</template><script lang="ts">
import AlertDialog from "$lib/components/markas/AlertDialog.svelte";
import Button from "$lib/components/markas/Button.svelte";
</script>
<AlertDialog
title="Delete your account?"
variant="danger"
actionLabel="Delete account"
onaction={deleteAccount}
>
{#snippet trigger()}
<Button variant="danger">Delete account</Button>
{/snippet}
All of your projects and invoices will be removed. You cannot undo this
action.
</AlertDialog>---
import AlertDialog from "@/components/markas/AlertDialog.astro";
import Button from "@/components/markas/Button.astro";
---
<AlertDialog
title="Delete your account?"
variant="danger"
actionLabel="Delete account"
>
<Button slot="trigger" variant="danger">Delete account</Button>
All of your projects and invoices will be removed. You cannot undo this
action.
</AlertDialog>A small bundled script opens every alert dialog on the page and dispatches a bubbling markas-action or markas-cancel event from the dialog when it closes.
import { Component } from "@angular/core";
import { AlertDialog } from "./markas/alert-dialog.component";
import { Button } from "./markas/button.component";
@Component({
selector: "app-delete-account",
imports: [AlertDialog, Button],
template: `
<markas-alert-dialog
title="Delete your account?"
variant="danger"
actionLabel="Delete account"
(action)="deleteAccount()"
>
<button markas-button trigger variant="danger">Delete account</button>
All of your projects and invoices will be removed. You cannot undo this
action.
</markas-alert-dialog>
`,
})
export class DeleteAccount {
deleteAccount() {}
}- Unlike Modal, clicking the backdrop does not close the dialog. The user must choose cancel or the action; Escape counts as cancel.
- Focus starts on the cancel button.
dialog.returnValueisactionorcancelin thecloseevent.- The buttons read “Cancel” and “Continue” by default. Translate them with
cancelLabelandactionLabel(Blade:cancel-label,action-label).
Props
| Name | Type | Default | Description |
|---|---|---|---|
title | string | - | Dialog title, used for aria-labelledby. |
children / slot | slot / ReactNode / snippet | - | Short explanation of the consequence, used for aria-describedby. |
trigger | slot / ReactNode / snippet | - | Element that opens the dialog when clicked. Angular: an element with the trigger attribute. |
variant | default | danger | default | Color of the action button. Use danger for destructive or irreversible actions. |
cancelLabel | string | Cancel | Text of the cancel button. |
actionLabel | string | Continue | Text of the action button. |
onAction / @action / markas-action | () => void | - | Called when the action button is chosen. Svelte: onaction. Blade and Astro dispatch a markas-action event. |
onCancel / @cancel / markas-cancel | () => void | - | Called when the dialog closes through the cancel button or Escape. Svelte: oncancel. Blade and Astro dispatch a markas-cancel event. |
id | string | auto | Dialog id. Use it to open the dialog from elsewhere with showModal(). |
action | output<void> | - | Angular only. Emits when the action button is chosen. |
cancelled | output<void> | - | Angular only. Emits when the dialog closes through the cancel button or Escape. |
Accessibility
- Uses dialog with role=alertdialog and showModal(), so focus stays inside and the page behind is inert.
- The title is linked with aria-labelledby and the explanation with aria-describedby.
- Focus starts on the cancel button, so pressing Enter by accident never runs the action.
- Escape closes the dialog and counts as cancel. Clicking the backdrop does nothing.
Related components
More overlay components with the same classes in every framework.
- Command PaletteSearchable list of commands in a modal dialog, filtered as you type, with arrow key navigation and an optional Ctrl+K or Cmd+K shortcut.
- Context MenuMenu opened by right-clicking an area or pressing Shift+F10, shown at the pointer through the Popover API with WAI-ARIA Menu keyboard support.
- DrawerFull-height side panel built on the native dialog element, sliding in from the right or left.
- Dropdown MenuAction menu built on the Popover API, with keyboard navigation following the WAI-ARIA Menu Button pattern.
- Hover CardPreview card built on the Popover API, shown when a link is hovered or focused, for profiles, repositories, and other previews.
- ModalModal dialog built on the native dialog element, with focus trapping and a close button.