suiss/ui · Component
Dialog
A modal window that appears above the page to focus people on a task or message.
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.
Dialog wraps the dialog primitive of the chosen base. The Dialog root manages the open state, and DialogTrigger opens it. DialogContent renders the window in a portal over a dimmed DialogOverlay, with a close button in the top corner by default. Inside it, DialogHeader holds the DialogTitle and DialogDescription, and DialogFooter holds the actions. DialogClose closes the dialog from any element.
Use a dialog for a short, focused task such as editing a few fields. To confirm a destructive or important action that needs an explicit response, consider an alert dialog. For larger content that slides in from an edge, use a sheet or drawer.
Installation
CLI
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Manual
- Install the dependencies and add the
cnhelper:
-
Add the pieces it builds on: Button,
use-scrollbar-gap. -
Copy the source into
components/ui/dialog.tsx:
- Update the import paths to match your project.
Usage
The dialog is uncontrolled by default; set defaultOpen to start open, or control it with open and onOpenChange. Render the trigger as another component, such as a Button, with the render prop. Use DialogClose with render for a Cancel button.
The dialog is uncontrolled by default; set defaultOpen to start open, or control it with open and onOpenChange. Set asChild on DialogTrigger to render your own Button as the trigger, and on DialogClose for a Cancel button.
The dialog is uncontrolled by default; set defaultOpen to start open, or control it with isOpen and onOpenChange. The first pressable child of Dialog, such as a Button, opens it. Give a Button slot="close" for a Cancel button.
Set showCloseButton={false} on DialogContent to remove the corner close button, and set closeLabel to replace its icon with a text label. Set showCloseButton on DialogFooter to add a secondary Close button to the actions. The footer stacks its actions in reverse order on small screens and aligns them to the end on wider screens.
Examples
Without close button
A dialog with no corner close button that adds a Close action to the footer instead.
Destructive
A dialog that confirms deleting a project, with a destructive action and a Cancel button.
API Reference
Dialog
The root that manages the dialog's open state.
Also accepts the props of the primitive part it wraps.
DialogTrigger
The button that opens the dialog.
Also accepts the props of the primitive part it wraps.
DialogPortal
Renders its children into a portal outside the current DOM hierarchy.
Also accepts the props of the primitive part it wraps.
DialogClose
A button that closes the dialog.
Also accepts the props of the primitive part it wraps.
DialogOverlay
The dimmed layer behind the dialog.
Also accepts the props of the primitive part it wraps.
DialogContent
The dialog window, rendered in a portal with an overlay and an optional close button.
| Prop | Type | Default | Description |
|---|---|---|---|
showCloseButton | boolean | true | Shows the close button in the top corner. |
closeLabel | string | - | Replaces the close button's icon with this text. |
Also accepts the props of the primitive part it wraps.
DialogHeader
Groups the title and description.
Also accepts the props of React.ComponentProps<"div">.
DialogFooter
Holds the dialog's actions.
| Prop | Type | Default | Description |
|---|---|---|---|
showCloseButton | boolean | false | Adds a secondary Close button after the footer's actions. |
Also accepts the props of React.ComponentProps<"div">.
DialogTitle
The dialog's title, which also names it for assistive technology.
Also accepts the props of the primitive part it wraps.
DialogDescription
Supporting text that describes the dialog for assistive technology.
Also accepts the props of the primitive part it wraps.
Accessibility
- The window has the
dialogrole.DialogTitleprovides its accessible name andDialogDescriptionits accessible description. - Opening the dialog moves focus inside it. Escape closes it and returns focus to the trigger.
- The icon-only close button has a visually hidden
Closelabel. - Always include a
DialogTitle; hide it visually withsr-onlyif the design has no visible title.
Notes
- Styling hooks:
data-slotvaluesdialog-overlay,dialog-content,dialog-close,dialog-header,dialog-footer,dialog-titleanddialog-description. data-openanddata-closeddrive the fade and zoom animation.- The window is
sm:max-w-mdby default; override it withclassNameonDialogContent. - When a close button is shown, the first child of the content gets extra end padding so it does not run under the button.
- Uses the
popover,secondaryandmuted-foregroundcolors, with abg-black/50backdrop.
Web preview
Dialog opens a centered card over a dimmed scrim. DialogContent renders through a portal (inside a full-window overlay on iOS), scales and fades in, and shows a round close button in the top-right corner by default. Tapping the scrim closes the dialog.
Use it for short forms and information that the user can dismiss freely. When the user must make an explicit choice, use Alert Dialog instead.
Installation
The CLI also adds what it builds on: Button, Icon, Text. On React Native it also adds the animated view components/ui/animated-view.tsx.
Manual
- Install the dependencies:
-
Add the pieces it builds on: Button, Icon, Text, and the primitives
components/primitives/dialog.tsx,components/primitives/use-render.tsx, and the animated viewcomponents/ui/animated-view.tsxfrom the next step. -
Copy the animated view into
components/ui/animated-view.tsx:
- Copy the source into
components/ui/dialog.tsx:
- Update the import paths to match your project.
- Install the dependencies:
-
Add the pieces it builds on: Button, Icon, Text, and the primitives
components/primitives/dialog.tsx,components/primitives/use-render.tsx, and the animated viewcomponents/ui/animated-view.tsxfrom the next step. -
Copy the animated view into
components/ui/animated-view.tsx:
- Copy the source into
components/ui/dialog.tsx:
- Update the import paths to match your project.
- Install the dependencies:
-
Add the pieces it builds on: Button, Icon, Text, and the primitives
components/primitives/dialog.tsx,components/primitives/use-render.tsx, and the animated viewcomponents/ui/animated-view.tsxfrom the next step. -
Copy the animated view into
components/ui/animated-view.tsx:
- Copy the source into
components/ui/dialog.tsx:
- Update the import paths to match your project.
-
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.
- Set
minSdkto 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
Compose DialogTrigger and DialogContent with a DialogHeader (DialogTitle, DialogDescription), your content, and a DialogFooter. Footer buttons stack vertically with the first child at the bottom, and sit in a row aligned to the end on wider screens. Use DialogClose with render to turn any Button into a close button.
Set showCloseButton={false} on the content to hide the corner button, or pass closeLabel to show a text button such as "Done" instead of the icon. The header adds end padding so the title does not run under it. DialogFooter takes showCloseButton to append a secondary Close button.
Use open and onOpenChange for controlled state, or defaultOpen for uncontrolled.
Examples
Default
Web preview
Destructive
A destructive action with a cancel button in the footer.
Web preview
Without close button
No corner button, with a Close button in the footer.
Web preview
With close label
A text close button through closeLabel.
Web preview
API Reference
Dialog
The root that manages the open state.
| Prop | Type | Default | Description |
|---|---|---|---|
open | boolean | - | Whether the dialog is open, for controlled use. |
defaultOpen | boolean | false | Whether the dialog starts open when uncontrolled. |
onOpenChange | (open: boolean, details) => void | - | Called when the dialog opens or closes. |
modal | boolean | true | Blocks interaction with the rest of the screen while open. |
disablePointerDismissal | boolean | false | Keeps the dialog open when the overlay is tapped. |
DialogOverlay
Dimmed scrim that closes the dialog when tapped.
Also accepts the props of React.ComponentProps<typeof DialogPrimitive.Backdrop>.
DialogContent
Centered card with an optional close button.
| Prop | Type | Default | Description |
|---|---|---|---|
portalHost | string | - | Name of the portal host to render into. |
showCloseButton | boolean | true | Shows the corner close button. Defaults to true. |
closeLabel | string | - | Text for the close button instead of the icon. |
Also accepts the props of React.ComponentProps<typeof DialogPrimitive.Popup>.
DialogHeader
Column for the title and description.
Also accepts the props of ViewProps.
DialogFooter
Area for actions.
| Prop | Type | Default | Description |
|---|---|---|---|
showCloseButton | boolean | false | Appends a secondary Close button. |
Also accepts the props of ViewProps.
DialogTitle
Dialog heading.
Also accepts the props of React.ComponentProps<typeof DialogPrimitive.Title>.
DialogDescription
Supporting text.
Also accepts the props of React.ComponentProps<typeof DialogPrimitive.Description>.
Accessibility
- The popup has the
dialogrole, is labelled by the title and is marked as modal for VoiceOver. - Focus moves to the title when the dialog opens.
- The Android back button and the VoiceOver escape gesture close it.
- The icon close button is labelled "Close".
Notes
- On iOS the content is wrapped in a full-window overlay so it appears above native navigation.
- Animations respect the system Reduce Motion setting.
- Uses
bg-popover,bg-black/50andbg-secondarytokens; light and dark follow the system appearance.