Dialog
Ask for a decision with clear primary and secondary actions, including pending and retry states.
npx @swipeui/cli add dialogWhen to use it
- Confirming important actions, such as Delete project? or Sign out?
- Short decisions with two or three clear options.
- Errors that must be acknowledged before continuing.
- Actions that run on a server and should keep the dialog open if they fail.
When not to use it
- Non-blocking messages. Use Toast or Alert.
- Lists of actions. Use Action sheet.
- Forms or long content. Use Sheet.
Installation
Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.
npx @swipeui/cli add dialog- Adds
components/swipeui/overlay/dialog.tsxand 11 shared helpers. - Installs react-native-reanimated, react-native-worklets, uniwind, clsx, tailwind-merge, expo-haptics, class-variance-authority, react-native-gesture-handler, react-native-safe-area-context. In Expo apps it uses
npx expo installso versions match your SDK.
Setup
Place OverlayProvider inside SafeAreaProvider near the application root. Register OverlayScope inside each native modal screen or native sheet content. Root absolute views alone cannot establish layering across native windows. Native cross-window presentation remains unverified.
Usage
import { Dialog } from '@/components/swipeui/overlay/dialog';
<Dialog
title="Remove saved route?"
triggerLabel="Remove"
actions={[
{ id: 'remove', label: 'Remove', destructive: true },
{ id: 'cancel', label: 'Cancel' },
]}
/>;API reference
| Prop | Type | Default | Description |
|---|---|---|---|
title | | — | Visible title and initial accessibility focus. |
description? | | — | Supporting message. |
icon? | | — | Optional decorative icon for the subject of the dialog. |
children? | | — | Optional body, such as an input field or the terms scroll region. |
contentAlign? | | | Position body copy and the inline footer. |
showClose? | | | Display the optional close control in the header. |
closeStyle? | | | Use a plain corner control. |
initialFocusRef? | | — | Optional field or control to focus when the dialog opens. Defaults to the heading. |
secondaryVariant? | | | Secondary action appearance. |
pillActions? | | | Render actions as capsules. |
fixedActions? | | | Keep the header and actions outside a caller-provided scroll region. |
backdropContent? | | — | Optional custom visual backdrop. Outside dismissal continues to work. |
clearBackdrop? | | | Hide the dim surface so a custom backdrop is visible. |
actions | | — | Actions; successful completion closes the dialog. |
presentation? | | | Surface location; ActionSheet uses sheet. |
materialTone? | | — | Semantic Glass tint for the panel. |
tone? | | | Native visual convention. |
open? | | — | Controlled visibility. |
defaultOpen? | | | Initial visibility. |
onOpenChange? | | — | Reports visibility intent. |
triggerLabel? | | — | Optional built-in trigger. |
triggerStyle? | | | Built-in trigger appearance. |
actionLayout? | | | Action arrangement. |
dismissible? | | | Permit backdrop/back/escape dismissal. |
primaryActionId? | | — | Action emphasized in the dialog. Defaults to the first enabled action. |
messages? | | — | Localized submission and failure text. |
onActionError? | | — | Error handler; operations are never logged. |
disabled? | | — | Disable trigger/actions. |
haptics? | | — | Action feedback. |
motion? | | — | Shared overlay/press character. |
className? | | — | Trigger wrapper classes. |
testID? | | — | Root identifier. |
Composition and behavior
- title and description above actions, each with an id, label, onPress, destructive and disabled.
- presentation is alert or sheet; tone is ios or material; actionLayout is stacked or inline.
- triggerLabel adds a built-in button; or control with open and onOpenChange.
- dismissible controls backdrop and back dismissal.
Use primaryActionId for the action to emphasize. A rejected callback leaves the dialog open with an inline message. Set messages.pending and messages.actionError to localize progress and retry guidance.
Composing a dialog
| Setting | Behavior |
|---|---|
children, icon | Add an input, a fixed-height scroll region or a decorative icon. |
contentAlign, pillActions, secondaryVariant | Choose leading or centred copy, capsule actions, and a ghost or outlined secondary action. |
fixedActions, showClose | Keep the header and actions outside a scrollable body and optionally show an accessible close icon. |
backdropContent, clearBackdrop | Paint an optional backdrop layer and choose whether to show the default dim scrim. Respect Reduce Transparency in an app-provided blur layer. |
triggerStyle | Use the plain or tinted built-in trigger. |
For a destructive input confirmation, hold the draft in the caller and disable Delete until the phrase matches exactly. Pass the input ref through initialFocusRef when the confirmation should open with the keyboard. For long terms, use closeStyle="plain" to simplify the header and keep the agree action outside the scroll region. Each action can override variant, size, className and textClassName.
Behavior and gestures
- Opens over the screen with a dimmed backdrop.
- Tap an action to run it; the dialog closes when it succeeds and stays open if it fails.
- While an action runs, other actions and dismissal are blocked.
- Tap the backdrop, press back or use the escape gesture to dismiss, unless dismissible is false.
- Actions stack vertically by default or sit side by side with actionLayout="inline".
Accessibility
- Focus moves to the title when it opens and returns when it closes.
- Only the top dialog is accessible; a dialog on top of another hides the one below.
- Each action is a named button; destructive actions look destructive and should say what they do, like "Delete project".
- Errors are passed to onActionError and never logged.
Motion
- Uses the
pressandoverlaymotion roles, so it follows your app's feel. Passmotionto tune this one instance. - Opens and closes with the overlay role.
- Reduce Motion uses a short fade.
Performance
- Nothing is rendered while closed.
Notes for AI
- Return a promise from onPress for async actions; give every action an id and label.
Compatibility
| Runs on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.