suiss/ui · Component
Alert Dialog
A modal dialog that interrupts the user to confirm an important action or acknowledge information.
Alert Dialog is an open-source component from suiss/ui for React, React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.
Alert Dialog wraps the alert dialog primitive of the chosen base. An AlertDialog root contains an AlertDialogTrigger and an AlertDialogContent. The content renders its own portal and scrim overlay, and typically holds an AlertDialogHeader (with optional AlertDialogMedia, plus AlertDialogTitle and AlertDialogDescription) followed by an AlertDialogFooter with AlertDialogCancel and AlertDialogAction buttons.
Use it when a decision must be made before continuing, such as signing out or deleting data. Unlike a regular dialog, it is not dismissed by clicking outside. For a choice of actions anchored to the bottom of the screen, use Alert Sheet.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Usage
Composition
Use the following composition to build a AlertDialog:
Examples
Small
Set size="sm" on AlertDialogContent for a narrower dialog. This one also has a destructive action.
With media
Add an AlertDialogMedia to the header to show an icon above the title.
Accessibility
- The popup has the
alertdialogrole, named byAlertDialogTitleand described byAlertDialogDescription. - Opening moves focus into the dialog; closing returns focus to the trigger.
Escapecloses the dialog.- Clicking the overlay does not close it; a choice must be made with a footer button or
Escape.
API Reference
AlertDialog
The root that manages the open state.
Also accepts the props of the primitive part it wraps.
The dialog is uncontrolled by default; use defaultOpen, or control it with open and onOpenChange.
The dialog is uncontrolled by default; use defaultOpen, or control it with isOpen and onOpenChange.
AlertDialogTrigger
The control that opens the dialog.
Also accepts the props of the primitive part it wraps.
AlertDialogPortal
Renders the dialog into a portal outside the DOM hierarchy.
Also accepts the props of the primitive part it wraps.
AlertDialogOverlay
The full-screen scrim behind the dialog.
Also accepts the props of the primitive part it wraps.
AlertDialogContent
The dialog surface, rendered with its own portal and overlay.
| Prop | Type | Default |
|---|---|---|
size | "default" | "sm" | "default" |
| Prop | Type | Default |
|---|---|---|
isDismissable | boolean | false |
isKeyboardDismissDisabled | boolean | - |
isDismissable closes the dialog on a press outside it, and isKeyboardDismissDisabled stops Escape from closing it.
Also accepts the props of the primitive part it wraps.
AlertDialogContent already includes AlertDialogPortal and AlertDialogOverlay, so you rarely use those parts directly. size sets the maximum width; sm is narrower than default.
Enter and exit use fade and zoom animations keyed to data-open and data-closed.
Enter and exit use fade and zoom animations keyed to data-state="open" and data-state="closed".
Enter and exit use fade and zoom animations keyed to data-entering and data-exiting.
AlertDialogHeader
A centered layout wrapper for the media, title and description.
Also accepts the props of React.ComponentProps<"div">.
AlertDialogFooter
A two-column grid for the cancel and action buttons.
Also accepts the props of React.ComponentProps<"div">.
AlertDialogMedia
A circular container for an icon or image above the title.
Also accepts the props of React.ComponentProps<"div">.
AlertDialogTitle
The heading that names the dialog.
Also accepts the props of the primitive part it wraps.
AlertDialogDescription
Supporting text that describes the dialog.
Also accepts the props of the primitive part it wraps.
AlertDialogAction
A button that confirms and closes the dialog.
| Prop | Type | Default |
|---|---|---|
variant | "default" | "outline" | "secondary" | "tinted" | "ghost" | "plain" | "destructive" | "link" | "default" |
size | "default" | "xs" | "sm" | "lg" | "xl" | "form" | "icon" | "icon-xs" | "icon-sm" | "icon-lg" | "icon-xl" | "default" |
Also accepts the props of the primitive part it wraps.
Also accepts the props of Button.
variant and size are the Button variant and size. Use variant="destructive" for irreversible operations.
AlertDialogCancel
A button that dismisses the dialog without acting.
| Prop | Type | Default |
|---|---|---|
variant | "default" | "outline" | "secondary" | "tinted" | "ghost" | "plain" | "destructive" | "link" | "secondary" |
size | "default" | "xs" | "sm" | "lg" | "xl" | "form" | "icon" | "icon-xs" | "icon-sm" | "icon-lg" | "icon-xl" | "default" |
Also accepts the props of the primitive part it wraps.
Also accepts the props of Button.
Both AlertDialogCancel and AlertDialogAction close the dialog and render a Button, styled with the Button variant and size. Each part sets a data-slot, such as alert-dialog-content or alert-dialog-cancel, for styling, and the content also sets data-size.
Web preview
AlertDialog is a modal that cannot be dismissed by tapping the scrim. AlertDialogContent renders through a portal (inside a full-window overlay on iOS) with a dimmed scrim and a centered card that scales and fades in.
Use it for confirmations that need an explicit choice, such as deleting data. For less critical content that can be dismissed freely, use Dialog; for a list of choices anchored to the bottom of the screen, use Alert Sheet.
Installation
- Install the following dependencies:
-
Copy the animated view into
components/ui/animated-view.tsx:
- Copy the primitives it uses into
components/primitives:
- Copy and paste the following code into
components/ui/alert-dialog.tsx:
- Update the import paths to match your project setup.
- Install the following dependencies:
-
Copy the animated view into
components/ui/animated-view.tsx:
- Copy the primitives it uses into
components/primitives:
- Copy and paste the following code into
components/ui/alert-dialog.tsx:
- Update the import paths to match your project setup.
- Install the following dependencies:
-
Copy the animated view into
components/ui/animated-view.tsx:
- Copy the primitives it uses into
components/primitives:
- Copy and paste the following code into
components/ui/alert-dialog.tsx:
- Update the import paths to match your project setup.
-
Target iOS 17 or later.
-
Add the Swift package to your app:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Add the files to your app target.
- Apply the Compose compiler plugin, enable Compose, set
compileSdkto 37 or higher andminSdkto 24 or higher, and add the dependencies:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Update the
com.esuiss.uipackage names to match your project.
Usage
Examples
Default
Web preview
Small
Set size to sm for a narrower dialog.
Web preview
With media
Add an AlertDialogMedia above the title to show an icon badge.
Web preview
This code uses Tailwind classes that need Uniwind or NativeWind. With StyleSheet, pass the same values through the style props.
Destructive
Set the action's variant to destructive for an irreversible confirmation.

Accessibility
- The popup has the
alertdialogrole, is labelled by the title and is marked as modal for VoiceOver. - Focus moves to the title when the dialog opens.
- Tapping the scrim does not close it; the Android back button and the VoiceOver escape gesture do.
- The title has the
headingrole, and the action buttons have thebuttonrole.
API Reference
AlertDialog
The root that manages the open state.
| Prop | Type | Default |
|---|---|---|
open | boolean | - |
defaultOpen | boolean | false |
onOpenChange | (open: boolean, details) => void | - |
Use open and onOpenChange for controlled state, or defaultOpen for uncontrolled. onOpenChange is called when the dialog opens or closes.
AlertDialogOverlay
Dimmed scrim behind the dialog.
Also accepts the props of React.ComponentProps<typeof AlertDialogPrimitive.Backdrop>.
AlertDialogContent
Centered card with scale and fade transitions.
| Prop | Type | Default |
|---|---|---|
portalHost | string | - |
size | "default" | "sm" | "default" |
Also accepts the props of React.ComponentProps<typeof AlertDialogPrimitive.Popup>.
size sets the maximum width; sm is narrower than default. Pass portalHost to render into a named portal host. On iOS the content is wrapped in a full-window overlay so it appears above native navigation. Enter and exit animations respect the system Reduce Motion setting.
AlertDialogHeader
Centered column for the title and description.
Also accepts the props of ViewProps.
AlertDialogFooter
Row of actions with equal-width buttons.
Also accepts the props of ViewProps.
Both footer buttons close the dialog and stretch to equal widths.
AlertDialogMedia
Round badge for an icon above the title.
Also accepts the props of ViewProps.
AlertDialogTitle
Dialog heading.
Also accepts the props of React.ComponentProps<typeof AlertDialogPrimitive.Title>.
AlertDialogDescription
Supporting text below the title.
Also accepts the props of React.ComponentProps<typeof AlertDialogPrimitive.Description>.
AlertDialogAction
Button that confirms and closes the dialog.
Also accepts the props of React.ComponentProps<typeof AlertDialogPrimitive.Close>, React.ComponentProps<typeof Button>.
AlertDialogCancel
Secondary button that closes the dialog.
Also accepts the props of React.ComponentProps<typeof AlertDialogPrimitive.Close>, React.ComponentProps<typeof Button>.
AlertDialogAction and AlertDialogCancel accept the Button variant and size. Use variant="destructive" on the action for destructive confirmations.
.alertDialog
| Parameter | Type | Default |
|---|---|---|
isPresented | Binding<Bool> | - |
content | () -> Content | - |
AlertDialogContent
Centered card with scale and fade transitions.
| Parameter | Type | Default |
|---|---|---|
size | Size: .default | .sm | .default |
content | () -> Content | - |
AlertDialogHeader
Centered column for the title and description.
| Parameter | Type | Default |
|---|---|---|
content | () -> Content | - |
AlertDialogMedia
Round badge for an icon above the title.
| Parameter | Type | Default |
|---|---|---|
content | () -> Content | - |
AlertDialogTitle
Dialog heading.
| Parameter | Type | Default |
|---|---|---|
_Â title | LocalizedStringKey | - |
verbatim | String | - |
Overloads: init(_:), init(verbatim:).
AlertDialogDescription
Supporting text below the title.
| Parameter | Type | Default |
|---|---|---|
_Â description | LocalizedStringKey | - |
verbatim | String | - |
Overloads: init(_:), init(verbatim:).
AlertDialogFooter
Row of actions with equal-width buttons.
| Parameter | Type | Default |
|---|---|---|
content | () -> Content | - |
AlertDialogAction
Button that confirms and closes the dialog.
| Parameter | Type | Default |
|---|---|---|
variant | VariantButtonStyle.Variant | .default |
size | VariantButtonStyle.Size | .default |
action | (() -> Void)? | nil |
label | () -> Label | - |
_Â title | LocalizedStringKey | - |
Overloads: init(variant:size:action:label:), init(_:variant:size:action:).
AlertDialogCancel
Secondary button that closes the dialog.
| Parameter | Type | Default |
|---|---|---|
variant | VariantButtonStyle.Variant | .secondary |
size | VariantButtonStyle.Size | .default |
action | (() -> Void)? | nil |
label | () -> Label | - |
_Â title | LocalizedStringKey | "Cancel" |
Overloads: init(variant:size:action:label:), init(_:variant:size:action:).
AlertDialogSize
Values: Default, Sm.
AlertDialog
The root that manages the open state.
| Parameter | Type | Default |
|---|---|---|
open | Boolean | - |
onOpenChange | (Boolean) -> Unit | - |
modifier | Modifier | Modifier |
size | AlertDialogSize: Default | Sm | AlertDialogSize.Default |
content | @Composable ColumnScope.() -> Unit | - |
AlertDialogHeader
Centered column for the title and description.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
content | @Composable ColumnScope.() -> Unit | - |
AlertDialogMedia
Round badge for an icon above the title.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
content | @Composable BoxScope.() -> Unit | - |
AlertDialogTitle
Dialog heading.
| Parameter | Type | Default |
|---|---|---|
text | String | - |
modifier | Modifier | Modifier |
AlertDialogDescription
Supporting text below the title.
| Parameter | Type | Default |
|---|---|---|
text | String | - |
modifier | Modifier | Modifier |
AlertDialogFooter
Row of actions with equal-width buttons.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
content | @Composable RowScope.() -> Unit | - |
AlertDialogAction
Button that confirms and closes the dialog.
Receiver: RowScope.
| Parameter | Type | Default |
|---|---|---|
text | String | - |
onClick | () -> Unit | - |
modifier | Modifier | Modifier |
variant | ButtonVariant | ButtonVariant.Default |
size | ButtonSize | ButtonSize.Default |
AlertDialogCancel
Secondary button that closes the dialog.
Receiver: RowScope.
| Parameter | Type | Default |
|---|---|---|
text | String | - |
modifier | Modifier | Modifier |
onClick | () -> Unit | {} |
variant | ButtonVariant | ButtonVariant.Secondary |
size | ButtonSize | ButtonSize.Default |
