suiss/ui · Component
Alert Sheet
An action sheet that slides up from the bottom of the screen to confirm or choose an action.
Alert Sheet 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 Sheet is an iOS-style action sheet built on the dialog primitives of the chosen base. An AlertSheet root contains an AlertSheetTrigger and an AlertSheetContent, which renders its own portal and scrim overlay. Inside, an AlertSheetGroup holds an optional AlertSheetHeader (with AlertSheetTitle and AlertSheetDescription) and one or more AlertSheetAction rows. A separate AlertSheetCancel sits below the group.
Use it to offer a short list of actions tied to the current context, especially on touch devices. For a centered confirmation, use Alert Dialog.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
- Install the following dependencies and add the
cnhelper:
-
Add the pieces it builds on:
use-scrollbar-gap. -
Copy and paste the following code into your project.
- Update the import paths to match your project setup.
Usage
Composition
Use the following composition to build a AlertSheet:
Examples
With title
Leave AlertSheetTitle visible to show a title above the description.
Multiple actions
Put several AlertSheetAction rows in one group. Set variant="destructive" on the one that deletes.
Not dismissible
Set dismissible={false} to make the sheet an alert dialog: pressing outside does not close it, so one of the choices has to be made.
Accessibility
- With
dismissible(the default) the popup has thedialogrole; withdismissible={false}it has thealertdialogrole. - The popup is named by
AlertSheetTitleand described byAlertSheetDescription. - Focus moves to the cancel button on open and returns to the trigger on close.
Escapecloses the sheet.
API Reference
AlertSheet
The root that manages the open state and dismissal behavior.
| Prop | Type | Default |
|---|---|---|
dismissible | boolean | true |
Also accepts the props of the primitive part it wraps.
By default the sheet is dismissible and behaves like a regular dialog. Set dismissible={false} to render it as an alert dialog instead. Every action and the cancel button close the sheet.
Control the open state with open and onOpenChange, or use defaultOpen.
Control the open state with isOpen and onOpenChange, or use defaultOpen.
AlertSheetTrigger
The control that opens the sheet.
Also accepts the props of the primitive part it wraps.
AlertSheetPortal
Renders the sheet into a portal outside the DOM hierarchy.
Also accepts the props of the primitive part it wraps.
AlertSheetOverlay
The full-screen scrim behind the sheet.
Also accepts the props of the primitive part it wraps.
AlertSheetContent
The bottom-anchored container, rendered with its own portal and overlay.
Also accepts the props of the primitive part it wraps.
The sheet slides up from translate-y-full as it opens and back down as it closes, and its bottom padding respects env(safe-area-inset-bottom).
When the sheet opens, focus moves to AlertSheetCancel unless you pass your own initialFocus.
When the sheet opens, focus moves to AlertSheetCancel unless your onOpenAutoFocus calls event.preventDefault().
When the sheet opens, focus moves to AlertSheetCancel, which sets autoFocus by default.
AlertSheetGroup
A rounded surface that stacks the header and actions with dividers.
Also accepts the props of React.ComponentProps<"div">.
When an action contains an icon, the group switches to a grid so icons and labels align across rows.
AlertSheetHeader
A padded wrapper for the title and description.
Also accepts the props of React.ComponentProps<"div">.
AlertSheetTitle
The heading that names the sheet.
Also accepts the props of the primitive part it wraps.
Every sheet needs an AlertSheetTitle for its accessible name. If the title should not be visible, hide it with className="sr-only".
AlertSheetDescription
Supporting text that describes the sheet.
Also accepts the props of the primitive part it wraps.
AlertSheetAction
A full-width row button that performs an action and closes the sheet.
| Prop | Type | Default |
|---|---|---|
variant | "default" | "destructive" | "default" |
Also accepts the props of the primitive part it wraps.
variant sets the text color: default uses text-primary and destructive uses text-destructive.
AlertSheetCancel
A separate, bold button that dismisses the sheet.
Also accepts the props of the primitive part it wraps.
Each part sets a data-slot, such as alert-sheet-group or alert-sheet-cancel, for styling.
Web preview
AlertSheet presents a set of choices related to the current context. AlertSheetContent renders through a portal (inside a full-window overlay on iOS), slides up from the bottom over a dimmed scrim, and respects the safe-area insets.
Actions sit in an AlertSheetGroup, a rounded card that draws a hairline between each child, and AlertSheetCancel sits below it as its own card with bold text. Use it for two to a few actions; for a single decision that needs confirmation, use Alert Dialog.
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-sheet.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-sheet.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-sheet.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
Not dismissible
Set dismissible={false} so a tap on the scrim does not close the sheet. This example also has a destructive and a disabled action.
Web preview
Accessibility
- When dismissible the popup has the
dialogrole, otherwisealertdialog; it is labelled by the title and marked as modal for VoiceOver. - Focus moves to the title when the sheet opens.
- Actions have the
buttonrole with adisabledstate. - Separators between actions are hidden from screen readers.
API Reference
AlertSheet
Root that holds the open state.
| Prop | Type | Default |
|---|---|---|
dismissible | boolean | true |
Also accepts the props of AlertSheetPrimitive.RootProps.
By default the sheet is dismissible and a tap on the scrim closes it. Set dismissible={false} to require an explicit choice.
AlertSheetOverlay
Dimmed scrim behind the sheet.
Also accepts the props of React.ComponentProps<typeof AlertSheetPrimitive.Backdrop>.
AlertSheetContent
Bottom-anchored container that slides in and out.
| Prop | Type | Default |
|---|---|---|
portalHost | string | - |
Also accepts the props of React.ComponentProps<typeof AlertSheetPrimitive.Popup>.
Put an AlertSheetGroup inside, with an optional AlertSheetHeader and the AlertSheetAction rows, then an AlertSheetCancel. Pass portalHost to render into a named portal host. Padding uses the bottom and side safe-area insets, with a minimum of 8 points. On iOS the content is wrapped in a full-window overlay. Animations respect the system Reduce Motion setting.
AlertSheetGroup
Rounded card that separates its children with hairlines.
Also accepts the props of ViewProps.
AlertSheetHeader
Centered block for the title and description.
Also accepts the props of ViewProps.
AlertSheetTitle
Small, bold heading for the sheet.
Also accepts the props of React.ComponentProps<typeof AlertSheetPrimitive.Title>.
AlertSheetDescription
Supporting text below the title.
Also accepts the props of React.ComponentProps<typeof AlertSheetPrimitive.Description>.
AlertSheetAction
Full-width action row that closes the sheet.
| Prop | Type | Default |
|---|---|---|
variant | "default" | "destructive" | "default" |
Also accepts the props of React.ComponentProps<typeof AlertSheetPrimitive.Close>.
Every action closes the sheet when pressed, and string children are wrapped in Text automatically. variant sets the text color; use destructive on an action that deletes or removes. Set disabled to dim and block an action. Actions show opacity-80 while pressed.
AlertSheetCancel
Separate cancel card with bold text.
Also accepts the props of React.ComponentProps<typeof AlertSheetPrimitive.Close>.
.alertSheet
| Parameter | Type | Default |
|---|---|---|
isPresented | Binding<Bool> | - |
dismissible | Bool | true |
content | () -> Content | - |
AlertSheetContent
Bottom-anchored container that slides in and out.
| Parameter | Type | Default |
|---|---|---|
content | () -> Content | - |
AlertSheetGroup
Rounded card that separates its children with hairlines.
| Parameter | Type | Default |
|---|---|---|
content | () -> Content | - |
AlertSheetHeader
Centered block for the title and description.
| Parameter | Type | Default |
|---|---|---|
content | () -> Content | - |
AlertSheetTitle
Small, bold heading for the sheet.
| Parameter | Type | Default |
|---|---|---|
_Â title | LocalizedStringKey | - |
verbatim | String | - |
Overloads: init(_:), init(verbatim:).
AlertSheetDescription
Supporting text below the title.
| Parameter | Type | Default |
|---|---|---|
_Â description | LocalizedStringKey | - |
verbatim | String | - |
Overloads: init(_:), init(verbatim:).
AlertSheetActionVariant
Values: .default, .destructive.
AlertSheetAction
Full-width action row that closes the sheet.
| Parameter | Type | Default |
|---|---|---|
variant | AlertSheetActionVariant: .default | .destructive | .default |
action | (() -> Void)? | nil |
label | () -> Label | - |
_Â title | LocalizedStringKey | - |
icon | Image | - |
Overloads: init(variant:action:label:), init(_:variant:action:), init(_:icon:variant:action:).
AlertSheetCancel
Separate cancel card with bold text.
| Parameter | Type | Default |
|---|---|---|
action | (() -> Void)? | nil |
label | () -> Label | - |
_Â title | LocalizedStringKey | "Cancel" |
Overloads: init(action:label:), init(_:action:).
AlertSheetActionVariant
Values: Default, Destructive.
AlertSheet
Root that holds the open state.
| Parameter | Type | Default |
|---|---|---|
open | Boolean | - |
onOpenChange | (Boolean) -> Unit | - |
modifier | Modifier | Modifier |
dismissible | Boolean | true |
content | @Composable ColumnScope.() -> Unit | - |
AlertSheetGroup
Rounded card that separates its children with hairlines.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
content | @Composable () -> Unit | - |
AlertSheetHeader
Centered block for the title and description.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
content | @Composable ColumnScope.() -> Unit | - |
AlertSheetTitle
Small, bold heading for the sheet.
| Parameter | Type | Default |
|---|---|---|
text | String | - |
modifier | Modifier | Modifier |
AlertSheetDescription
Supporting text below the title.
| Parameter | Type | Default |
|---|---|---|
text | String | - |
modifier | Modifier | Modifier |
AlertSheetAction
Full-width action row that closes the sheet.
| Parameter | Type | Default |
|---|---|---|
text | String | - |
onClick | () -> Unit | - |
modifier | Modifier | Modifier |
variant | AlertSheetActionVariant: Default | Destructive | AlertSheetActionVariant.Default |
enabled | Boolean | true |
icon | ImageVector? | null |
AlertSheetCancel
Separate cancel card with bold text.
| Parameter | Type | Default |
|---|---|---|
text | String | "Cancel" |
modifier | Modifier | Modifier |
onClick | () -> Unit | {} |