Alert Dialog
---import { AlertDialog, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader, AlertDialogFooter, AlertDialogTitle, AlertDialogDescription, AlertDialogCancel, AlertDialogAction } from "@/components/starwind/alert-dialog";import { Button } from "@/components/starwind/button";---
<AlertDialog> <AlertDialogTrigger asChild> <Button variant="outline">Show Alert Dialog</Button> </AlertDialogTrigger> <AlertDialogContent> <AlertDialogHeader> <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle> <AlertDialogDescription> This action cannot be undone. This will permanently delete your account and remove your data from our servers. </AlertDialogDescription> </AlertDialogHeader> <AlertDialogFooter> <AlertDialogCancel>Cancel</AlertDialogCancel> <AlertDialogAction>Continue</AlertDialogAction> </AlertDialogFooter> </AlertDialogContent></AlertDialog>import { AlertDialog, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader, AlertDialogFooter, AlertDialogTitle, AlertDialogDescription, AlertDialogCancel, AlertDialogAction } from "@/components/starwind/alert-dialog";import { Button } from "@/components/starwind/button";
export function Example() { return ( <AlertDialog> <AlertDialogTrigger asChild> <Button variant="outline">Show Alert Dialog</Button> </AlertDialogTrigger> <AlertDialogContent> <AlertDialogHeader> <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle> <AlertDialogDescription> This action cannot be undone. This will permanently delete your account and remove your data from our servers. </AlertDialogDescription> </AlertDialogHeader> <AlertDialogFooter> <AlertDialogCancel>Cancel</AlertDialogCancel> <AlertDialogAction>Continue</AlertDialogAction> </AlertDialogFooter> </AlertDialogContent> </AlertDialog> );}<script setup lang="ts">import { AlertDialog, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader, AlertDialogFooter, AlertDialogTitle, AlertDialogDescription, AlertDialogCancel, AlertDialogAction,} from "@/components/starwind/alert-dialog";import { Button, ButtonVariants } from "@/components/starwind/button";</script>
<template> <AlertDialog> <AlertDialogTrigger asChild> <button :class="ButtonVariants.button({ variant: 'outline' })" type="button"> Show Alert Dialog </button> </AlertDialogTrigger> <AlertDialogContent> <AlertDialogHeader> <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle> <AlertDialogDescription> This action cannot be undone. This will permanently delete your account and remove your data from our servers. </AlertDialogDescription> </AlertDialogHeader> <AlertDialogFooter> <AlertDialogCancel>Cancel</AlertDialogCancel> <AlertDialogAction>Continue</AlertDialogAction> </AlertDialogFooter> </AlertDialogContent> </AlertDialog></template><script lang="ts"> import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@/components/starwind/alert-dialog"; import { Button } from "@/components/starwind/button";</script>
<div> <AlertDialog> <AlertDialogTrigger> {#snippet child({ props, children })} <Button {...props} variant="outline">{@render children?.()}</Button> {/snippet} Show Alert Dialog </AlertDialogTrigger> <AlertDialogContent> <AlertDialogHeader> <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle> <AlertDialogDescription> This action cannot be undone. This will permanently delete your account and remove your data from our servers. </AlertDialogDescription> </AlertDialogHeader> <AlertDialogFooter> <AlertDialogCancel>Cancel</AlertDialogCancel> <AlertDialogAction>Continue</AlertDialogAction> </AlertDialogFooter> </AlertDialogContent> </AlertDialog></div>Installation
pnpx starwind@latest add alert-dialog --framework astronpx starwind@latest add alert-dialog --framework astroyarn dlx starwind@latest add alert-dialog --framework astropnpx starwind@latest add alert-dialog --framework reactnpx starwind@latest add alert-dialog --framework reactyarn dlx starwind@latest add alert-dialog --framework reactpnpx starwind@latest add alert-dialog --framework vuenpx starwind@latest add alert-dialog --framework vueyarn dlx starwind@latest add alert-dialog --framework vuepnpx starwind@latest add alert-dialog --framework sveltenpx starwind@latest add alert-dialog --framework svelteyarn dlx starwind@latest add alert-dialog --framework svelteUsage
---import { AlertDialog, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader, AlertDialogFooter, AlertDialogTitle, AlertDialogDescription, AlertDialogCancel, AlertDialogAction } from "@/components/starwind/alert-dialog";import { Button } from "@/components/starwind/button";---
<AlertDialog> <AlertDialogTrigger asChild> <Button variant="outline">Show Alert Dialog</Button> </AlertDialogTrigger> <AlertDialogContent> <AlertDialogHeader> <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle> <AlertDialogDescription> This action cannot be undone. This will permanently delete your account and remove your data from our servers. </AlertDialogDescription> </AlertDialogHeader> <AlertDialogFooter> <AlertDialogCancel>Cancel</AlertDialogCancel> <AlertDialogAction>Continue</AlertDialogAction> </AlertDialogFooter> </AlertDialogContent></AlertDialog>import { AlertDialog, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader, AlertDialogFooter, AlertDialogTitle, AlertDialogDescription, AlertDialogCancel, AlertDialogAction } from "@/components/starwind/alert-dialog";import { Button } from "@/components/starwind/button";
export function Example() { return ( <AlertDialog> <AlertDialogTrigger asChild> <Button variant="outline">Show Alert Dialog</Button> </AlertDialogTrigger> <AlertDialogContent> <AlertDialogHeader> <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle> <AlertDialogDescription> This action cannot be undone. This will permanently delete your account and remove your data from our servers. </AlertDialogDescription> </AlertDialogHeader> <AlertDialogFooter> <AlertDialogCancel>Cancel</AlertDialogCancel> <AlertDialogAction>Continue</AlertDialogAction> </AlertDialogFooter> </AlertDialogContent> </AlertDialog> );}<script setup lang="ts">import { AlertDialog, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader, AlertDialogFooter, AlertDialogTitle, AlertDialogDescription, AlertDialogCancel, AlertDialogAction,} from "@/components/starwind/alert-dialog";import { Button, ButtonVariants } from "@/components/starwind/button";</script>
<template> <AlertDialog> <AlertDialogTrigger asChild> <button :class="ButtonVariants.button({ variant: 'outline' })" type="button"> Show Alert Dialog </button> </AlertDialogTrigger> <AlertDialogContent> <AlertDialogHeader> <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle> <AlertDialogDescription> This action cannot be undone. This will permanently delete your account and remove your data from our servers. </AlertDialogDescription> </AlertDialogHeader> <AlertDialogFooter> <AlertDialogCancel>Cancel</AlertDialogCancel> <AlertDialogAction>Continue</AlertDialogAction> </AlertDialogFooter> </AlertDialogContent> </AlertDialog></template><script lang="ts"> import { AlertDialog, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader, AlertDialogFooter, AlertDialogTitle, AlertDialogDescription, AlertDialogCancel, AlertDialogAction, } from "@/components/starwind/alert-dialog"; import { Button, ButtonVariants } from "@/components/starwind/button";</script>
<AlertDialog> <AlertDialogTrigger> {#snippet child({ props })} <button {...props} class={ButtonVariants.button({ variant: "outline" })} type="button" > Show Alert Dialog </button> {/snippet} </AlertDialogTrigger> <AlertDialogContent> <AlertDialogHeader> <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle> <AlertDialogDescription> This action cannot be undone. This will permanently delete your account and remove your data from our servers. </AlertDialogDescription> </AlertDialogHeader> <AlertDialogFooter> <AlertDialogCancel>Cancel</AlertDialogCancel> <AlertDialogAction>Continue</AlertDialogAction> </AlertDialogFooter> </AlertDialogContent></AlertDialog>Composition
Use this structure for an alert dialog:
AlertDialog├── AlertDialogTrigger└── AlertDialogContent ├── AlertDialogHeader │ ├── AlertDialogTitle │ └── AlertDialogDescription └── AlertDialogFooter ├── AlertDialogCancel └── AlertDialogActionWhen to Use
Use an alert dialog when the user must confirm a critical action or acknowledge important information before continuing.
Destructive Actions
Alert dialogs are commonly used to confirm destructive actions like deleting data.
---import { AlertDialog, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader, AlertDialogFooter, AlertDialogTitle, AlertDialogDescription, AlertDialogCancel, AlertDialogAction } from "@/components/starwind/alert-dialog";import { Button } from "@/components/starwind/button";---
<AlertDialog> <AlertDialogTrigger asChild> <Button variant="error">Delete Account</Button> </AlertDialogTrigger> <AlertDialogContent> <AlertDialogHeader> <AlertDialogTitle>Delete Account</AlertDialogTitle> <AlertDialogDescription> Are you sure you want to delete your account? This action is permanent and cannot be undone. All your data, including projects, settings, and personal information will be permanently removed. </AlertDialogDescription> </AlertDialogHeader> <AlertDialogFooter> <AlertDialogCancel>Cancel</AlertDialogCancel> <AlertDialogAction>Delete Account</AlertDialogAction> </AlertDialogFooter> </AlertDialogContent></AlertDialog>import { AlertDialog, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader, AlertDialogFooter, AlertDialogTitle, AlertDialogDescription, AlertDialogCancel, AlertDialogAction } from "@/components/starwind/alert-dialog";import { Button } from "@/components/starwind/button";
export function Example() { return ( <> <AlertDialog> <AlertDialogTrigger asChild> <Button variant="error">Delete Account</Button> </AlertDialogTrigger> <AlertDialogContent> <AlertDialogHeader> <AlertDialogTitle>Delete Account</AlertDialogTitle> <AlertDialogDescription> Are you sure you want to delete your account? This action is permanent and cannot be undone. All your data, including projects, settings, and personal information will be permanently removed. </AlertDialogDescription> </AlertDialogHeader> <AlertDialogFooter> <AlertDialogCancel>Cancel</AlertDialogCancel> <AlertDialogAction>Delete Account</AlertDialogAction> </AlertDialogFooter> </AlertDialogContent> </AlertDialog> </> );}<script setup lang="ts">import { AlertDialog, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader, AlertDialogFooter, AlertDialogTitle, AlertDialogDescription, AlertDialogCancel, AlertDialogAction,} from "@/components/starwind/alert-dialog";import { Button, ButtonVariants } from "@/components/starwind/button";</script>
<template> <AlertDialog> <AlertDialogTrigger asChild> <button :class="ButtonVariants.button({ variant: 'error' })" type="button"> Delete Account </button> </AlertDialogTrigger> <AlertDialogContent> <AlertDialogHeader> <AlertDialogTitle>Delete Account</AlertDialogTitle> <AlertDialogDescription> Are you sure you want to delete your account? This action is permanent and cannot be undone. All your data, including projects, settings, and personal information will be permanently removed. </AlertDialogDescription> </AlertDialogHeader> <AlertDialogFooter> <AlertDialogCancel>Cancel</AlertDialogCancel> <AlertDialogAction>Delete Account</AlertDialogAction> </AlertDialogFooter> </AlertDialogContent> </AlertDialog></template><script lang="ts"> import { AlertDialog, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader, AlertDialogFooter, AlertDialogTitle, AlertDialogDescription, AlertDialogCancel, AlertDialogAction, } from "@/components/starwind/alert-dialog"; import { Button, ButtonVariants } from "@/components/starwind/button";</script>
<AlertDialog> <AlertDialogTrigger> {#snippet child({ props })} <button {...props} class={ButtonVariants.button({ variant: "error" })} type="button" > Delete Account </button> {/snippet} </AlertDialogTrigger> <AlertDialogContent> <AlertDialogHeader> <AlertDialogTitle>Delete Account</AlertDialogTitle> <AlertDialogDescription> Are you sure you want to delete your account? This action is permanent and cannot be undone. All your data, including projects, settings, and personal information will be permanently removed. </AlertDialogDescription> </AlertDialogHeader> <AlertDialogFooter> <AlertDialogCancel>Cancel</AlertDialogCancel> <AlertDialogAction>Delete Account</AlertDialogAction> </AlertDialogFooter> </AlertDialogContent></AlertDialog>Custom Styling
You can customize the appearance of alert dialog components using the class prop.
---import { AlertDialog, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader, AlertDialogFooter, AlertDialogTitle, AlertDialogDescription, AlertDialogCancel, AlertDialogAction } from "@/components/starwind/alert-dialog";import { Button } from "@/components/starwind/button";---
<AlertDialog> <AlertDialogTrigger asChild> <Button variant="outline">Custom Alert</Button> </AlertDialogTrigger> <AlertDialogContent class="sm:max-w-md"> <AlertDialogHeader> <AlertDialogTitle class="text-center">Custom Alert Dialog</AlertDialogTitle> <AlertDialogDescription class="text-center"> This alert dialog has custom styling applied to make it more compact and centered. </AlertDialogDescription> </AlertDialogHeader> <AlertDialogFooter class="sm:justify-center"> <AlertDialogCancel class="w-full sm:w-auto">Cancel</AlertDialogCancel> <AlertDialogAction class="w-full sm:w-auto">Confirm</AlertDialogAction> </AlertDialogFooter> </AlertDialogContent></AlertDialog>import { AlertDialog, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader, AlertDialogFooter, AlertDialogTitle, AlertDialogDescription, AlertDialogCancel, AlertDialogAction } from "@/components/starwind/alert-dialog";import { Button } from "@/components/starwind/button";
export function Example() { return ( <> <AlertDialog> <AlertDialogTrigger asChild> <Button variant="outline">Custom Alert</Button> </AlertDialogTrigger> <AlertDialogContent className="sm:max-w-md"> <AlertDialogHeader> <AlertDialogTitle className="text-center">Custom Alert Dialog</AlertDialogTitle> <AlertDialogDescription className="text-center"> This alert dialog has custom styling applied to make it more compact and centered. </AlertDialogDescription> </AlertDialogHeader> <AlertDialogFooter className="sm:justify-center"> <AlertDialogCancel className="w-full sm:w-auto">Cancel</AlertDialogCancel> <AlertDialogAction className="w-full sm:w-auto">Confirm</AlertDialogAction> </AlertDialogFooter> </AlertDialogContent> </AlertDialog> </> );}<script setup lang="ts">import { AlertDialog, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader, AlertDialogFooter, AlertDialogTitle, AlertDialogDescription, AlertDialogCancel, AlertDialogAction,} from "@/components/starwind/alert-dialog";import { Button, ButtonVariants } from "@/components/starwind/button";</script>
<template> <AlertDialog> <AlertDialogTrigger asChild> <button :class="ButtonVariants.button({ variant: 'outline' })" type="button"> Custom Alert </button> </AlertDialogTrigger> <AlertDialogContent class="sm:max-w-md"> <AlertDialogHeader> <AlertDialogTitle class="text-center">Custom Alert Dialog</AlertDialogTitle> <AlertDialogDescription class="text-center"> This alert dialog has custom styling applied to make it more compact and centered. </AlertDialogDescription> </AlertDialogHeader> <AlertDialogFooter class="sm:justify-center"> <AlertDialogCancel class="w-full sm:w-auto">Cancel</AlertDialogCancel> <AlertDialogAction class="w-full sm:w-auto">Confirm</AlertDialogAction> </AlertDialogFooter> </AlertDialogContent> </AlertDialog></template><script lang="ts"> import { AlertDialog, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader, AlertDialogFooter, AlertDialogTitle, AlertDialogDescription, AlertDialogCancel, AlertDialogAction, } from "@/components/starwind/alert-dialog"; import { Button, ButtonVariants } from "@/components/starwind/button";</script>
<AlertDialog> <AlertDialogTrigger> {#snippet child({ props })} <button {...props} class={ButtonVariants.button({ variant: "outline" })} type="button" > Custom Alert </button> {/snippet} </AlertDialogTrigger> <AlertDialogContent class="sm:max-w-md"> <AlertDialogHeader> <AlertDialogTitle class="text-center">Custom Alert Dialog</AlertDialogTitle> <AlertDialogDescription class="text-center"> This alert dialog has custom styling applied to make it more compact and centered. </AlertDialogDescription> </AlertDialogHeader> <AlertDialogFooter class="sm:justify-center"> <AlertDialogCancel class="w-full sm:w-auto">Cancel</AlertDialogCancel> <AlertDialogAction class="w-full sm:w-auto">Confirm</AlertDialogAction> </AlertDialogFooter> </AlertDialogContent></AlertDialog>API Reference
Styled Component API
These props are added or materially changed by the installed styled component. Standard HTML attributes remain available through the inherited interfaces noted below. Expand a prop to see named type definitions and framework-specific imports. Follow the Primitive and Runtime links for lower-level behavior props.
Alert Dialog Trigger
Inherits button attributes.
Contains the following additional props:
asChild boolean false
- Description
- Merges the component behavior and props into its child element.
- Classification
- Primitive override
- Primitive prop
- alert-dialog.Trigger.asChild
Alert Dialog Action
Inherits Button props.
Contains the following additional props:
asChild boolean false
- Description
- Merges the component behavior and props into its child element.
- Classification
- Wrapper prop
Alert Dialog Cancel
Inherits Button props.
Contains the following additional props:
asChild boolean false
- Description
- Merges the component behavior and props into its child element.
- Classification
- Wrapper prop
Primitive And Runtime API
Use these references when you need the lower-level behavior APIs behind Alert Dialog.
Primitive API
Runtime API
- Alert Dialog primitive
createAlertDialogfrom@starwind-ui/runtime/alert-dialog
Changelog
View version history v2.1.0 4 releases
v2.1.0
- In Astro,
AlertDialogTriggerwithasChildnow makes your own element a working trigger. Before, a button child gave a control that did nothing. - In Astro, an attribute that you set on AlertDialog and its parts now wins over the component’s own default for the same attribute, such as
roleoraria-label. - In Svelte, a defined
openthat you pass when AlertDialog mounts now stays under your control, as in React and Vue. To change it, usebind:or update your state in the change callback. A form reset keeps it. If you passundefinedat mount, AlertDialog keeps its own state.
v2.0.3
- Vue Alert Dialog keeps its current open state when a change is canceled and responds to later open or close requests from your app.
- Trigger, action, and cancel buttons added after the dialog mounts now work without reopening it.
- Reduced background work when a React page uses multiple menus, tooltips, or other portals.
- Fixed nested Svelte overlays inside a dialog appearing behind their parent or failing to receive clicks.
- Fixed nested overlays appearing behind their parent in Vue and Svelte. Overlays can now render under the document body; if custom CSS or DOM queries require them to stay inside a parent, set a portal container or add
data-floating-rootto that parent. - Fixed React 18 retaining removed popup elements when the parent component stays mounted.
v2.0.2
- The default export in
index.tsnow has a name,AlertDialogParts, so framework tools show a clear name.
v2.0.0
- Alert Dialog now gets its behavior from Starwind Runtime. Runtime handles the modal state, focus, and closing of the confirmation dialog.
- See the Alert Dialog Primitive for the unstyled parts and the behavior API.