suiss/ui ยท Pattern
Context Actions
Actions for an element that open as a context menu on right click, or an action sheet on long press on mobile.
Context Actions is an open-source pattern 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.
ContextActions attaches a set of actions to an area of the page. On desktop it renders a ContextMenu that opens at the pointer on right click. Below the 48rem breakpoint it renders an AlertSheet instead, opened by a long press.
Use it for secondary actions on content such as photos, files or list rows, where actions should stay out of the way until requested.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
-
Add the
cnhelper. -
Add the pieces it builds on: Alert Sheet, Context Menu,
use-mobile. -
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 ContextActions:
Examples
With icons
Places an icon before every action. Set variant="destructive" on an item, here Delete, to style it as a destructive action.
Not dismissible
Set dismissible to false so the mobile sheet uses an alert dialog that closes only through an action or Cancel, not on an outside press.
Accessibility
- On desktop the popup has the
menurole and receives focus when opened; arrow keys move betweenmenuitems andEnterruns the focused one. Escapecloses the menu.- On mobile the trigger has
role="button",tabIndex={0}andaria-haspopup="dialog", and opens with theContextMenukey orShift+F10.
API Reference
ContextActions
The root that renders a ContextMenu on desktop and an AlertSheet on mobile.
| Prop | Type | Default |
|---|---|---|
onOpenChange | (open: boolean) => void | - |
dismissible | boolean | true |
children | React.ReactNode | - |
The open state is internal; use onOpenChange to react to it.
ContextActionsTrigger
The area that opens the actions on right click, or on long press and keyboard on mobile.
Also accepts the props of React.HTMLAttributes<HTMLElement>.
Wrap the target area in it. On mobile it opens the sheet on a 500 ms long press on touch, on the context menu event, or on the ContextMenu key or Shift+F10. A long press is cancelled if the finger moves more than 10 pixels, so scrolling over the trigger does not open the sheet. The trigger also disables text selection and the iOS touch callout so a long press does not select text.
ContextActionsContent
The popup holding the actions; on mobile it adds a Cancel button below them.
| Prop | Type | Default |
|---|---|---|
cancelLabel | string | "Cancel" |
Also accepts the props of React.HTMLAttributes<HTMLElement>.
Also accepts className, children, id and aria-label.
On mobile the sheet groups the items in a card and appends a Cancel button labelled by cancelLabel.
ContextActionsLabel
A non-interactive heading; a menu label on desktop and the sheet title on mobile.
Also accepts the props of React.HTMLAttributes<HTMLElement>.
Also accepts className, children and id.
ContextActionsItem
An actionable entry that closes the actions when chosen.
| Prop | Type | Default |
|---|---|---|
variant | "default" | "destructive" | - |
disabled | boolean | - |
Also accepts the props of React.HTMLAttributes<HTMLElement>.
Respond to the item with onAction. Also accepts className, children, id and aria-label.
ContextActionsSeparator
A divider between groups of items, rendered on desktop only.
Also accepts the props of React.HTMLAttributes<HTMLElement>.
Also accepts className.
Each part sets a data-slot, such as context-actions-trigger or context-actions-item, for styling.
Web preview
This code uses Tailwind classes that need Uniwind or NativeWind. With StyleSheet, pass the same values through the style props.
ContextActions turns any content into a long-press target. Holding ContextActionsTrigger for 500 ms opens an AlertSheet with the actions grouped in one block and a separate Cancel button below.
Use it for secondary actions on photos, messages or list rows that should not take up space on screen.
Installation
The CLI also adds what it builds on: Alert Sheet.
-
Add the pieces it builds on: Alert Sheet.
-
Copy and paste the following code into
components/patterns/context-actions.tsx:
- Update the import paths to match your project setup.
-
Add the pieces it builds on: Alert Sheet.
-
Copy and paste the following code into
components/patterns/context-actions.tsx:
- Update the import paths to match your project setup.
-
Add the pieces it builds on: Alert Sheet.
-
Copy and paste the following code into
components/patterns/context-actions.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
This code uses Tailwind classes that need Uniwind or NativeWind. With StyleSheet, pass the same values through the style props.
Examples
Inline
A small message bubble as the trigger, with a custom cancelLabel.

Accessibility
- The trigger has the hint "Long press for actions".
- It adds
longpressandshowActions("Show actions") accessibility actions, so screen reader users can open the sheet without holding. - Your own
accessibilityActionsandonAccessibilityActionare kept.
API Reference
ContextActions
The root that owns the open state.
| Prop | Type | Default |
|---|---|---|
onOpenChange | (open: boolean) => void | - |
dismissible | boolean | true |
children | React.ReactNode | - |
The open state is managed internally; use onOpenChange to react to it. Set dismissible to false so the sheet ignores outside presses.
ContextActionsTrigger
A Pressable that opens the sheet on long press.
Also accepts the props of React.ComponentProps<typeof Pressable>.
Wrap the target in it. onPress still works for a normal tap, and your own onLongPress runs before the sheet opens. Change the hold time with delayLongPress.
ContextActionsContent
The sheet with the grouped items and a Cancel button.
| Prop | Type | Default |
|---|---|---|
cancelLabel | string | "Cancel" |
Also accepts the props of React.ComponentProps<typeof AlertSheetContent>.
List ContextActionsItems in it, with a ContextActionsLabel first to show a title. On iOS the sheet renders in a full-window overlay so it appears above native screens.
ContextActionsLabel
A title shown at the top of the group.
Also accepts the props of React.ComponentProps<typeof AlertSheetTitle>.
ContextActionsItem
An actionable entry, rendered as an AlertSheetAction.
Also accepts the props of React.ComponentProps<typeof AlertSheetAction>.
ContextActionsSeparator
Kept for API parity; renders nothing.
| Prop | Type | Default |
|---|---|---|
className | string | - |
ContextActions
The root that owns the open state.
| Parameter | Type | Default |
|---|---|---|
dismissible | Bool | true |
cancelLabel | LocalizedStringKey | "Cancel" |
onOpenChange | ((Bool) -> Void)? | nil |
content | () -> Content | - |
label | () -> Label | - |
.contextActions
| Parameter | Type | Default |
|---|---|---|
dismissible | Bool | true |
cancelLabel | LocalizedStringKey | "Cancel" |
onOpenChange | ((Bool) -> Void)? | nil |
content | () -> Content | - |
ContextActions
The root that owns the open state.
| Parameter | Type | Default |
|---|---|---|
onOpenChange | (Boolean) -> Unit | {} |
dismissible | Boolean | true |
content | @Composable () -> Unit | - |
ContextActionsTrigger
The area that opens the actions on right click, or on long press and keyboard on mobile.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
enabled | Boolean | true |
label | String | "Show actions" |
content | @Composable BoxScope.() -> Unit | - |
ContextActionsContent
The sheet with the grouped items and a Cancel button.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
cancelLabel | String | "Cancel" |
content | @Composable () -> Unit | - |
ContextActionsLabel
A title shown at the top of the group.
| Parameter | Type | Default |
|---|---|---|
text | String | - |
modifier | Modifier | Modifier |
ContextActionsItem
An actionable entry, rendered as an AlertSheetAction.
| Parameter | Type | Default |
|---|---|---|
text | String | - |
onClick | () -> Unit | - |
modifier | Modifier | Modifier |
variant | MenuItemVariant | MenuItemVariant.Default |
enabled | Boolean | true |
icon | ImageVector? | null |
ContextActionsSeparator
Kept for API parity; renders nothing.
Takes no parameters.
