suiss/ui ยท Interaction
Preview Menu
A context menu that lifts the pressed item into an enlarged preview above its actions, like iOS context menus.
Preview Menu is an open-source interaction 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.
PreviewMenu builds on the menu primitives of the chosen base. Touching and holding the trigger, or right-clicking it, blurs the page and animates the trigger from its position into a centered preview up to 360px wide, morphing its corner radius along the way. The menu of actions opens below the preview and the trigger stays hidden until the menu finishes closing, so the preview appears to return to its place.
By default, the preview shows the trigger's own content. Pass preview to PreviewMenuContent to show richer content instead; the trigger's snapshot crossfades into it. Use it for items that benefit from a quick look before acting, such as photos, documents, or messages.
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:
- 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 PreviewMenu:
Examples
Disabled item
A disabled item is announced as unavailable and does not act, while the other items still work.
Custom preview
A compact album row opens a larger custom preview through the preview prop. Set aspectRatio when a custom preview has a different shape than the trigger; otherwise the preview keeps the trigger's proportions.
Accessibility
- The popup has
role="menu"and items haverole="menuitem", with keyboard navigation from the menu primitive. Escapecloses the menu without running an action.- Disabled items set
aria-disabledand cannot be chosen. - The lifted preview is
aria-hidden, so assistive technologies read the trigger and menu only.
API Reference
PreviewMenu
The root that manages open state and measures the preview frame.
| Prop | Type | Default |
|---|---|---|
open | boolean | - |
defaultOpen | boolean | false |
onOpenChange | (open: boolean) => void | - |
aspectRatio | number | - |
children | React.ReactNode | - |
Compose PreviewMenuTrigger and PreviewMenuContent inside PreviewMenu, with PreviewMenuItem and PreviewMenuSeparator inside the content. The menu is uncontrolled by default; pass open and onOpenChange to control it. aspectRatio is the width-to-height ratio of the preview and defaults to the trigger's ratio.
PreviewMenuTrigger
The element that opens the menu on touch and hold or right-click.
Also accepts the props of the primitive part it wraps.
The trigger carries data-previewing while open and data-lifted until the closing animation ends, and is invisible during that time. It disables text selection and the touch callout so long presses open the menu.
PreviewMenuContent
The backdrop, lifted preview, and popup that holds the menu items.
| Prop | Type | Default |
|---|---|---|
preview | React.ReactNode | - |
previewClassName | string | - |
Also accepts the props of the primitive part it wraps.
preview shows custom content in the preview instead of the trigger's content. previewClassName styles the clipped preview container.
PreviewMenuItem
An action in the menu.
| Prop | Type | Default |
|---|---|---|
variant | "default" | "destructive" | "default" |
| Prop | Type | Default |
|---|---|---|
disabled | boolean | - |
| Prop | Type | Default |
|---|---|---|
isDisabled | boolean | - |
Also accepts the props of the primitive part it wraps.
Handle actions with onClick on each item. Items close the menu when chosen. The destructive variant renders the label in the destructive color.
PreviewMenuSeparator
A thick divider between groups of items.
Also accepts the props of the primitive part it wraps.
Each part sets a data-slot, such as preview-menu-content, for styling. Items set data-variant.
Web preview
This code uses Tailwind classes that need Uniwind or NativeWind. With StyleSheet, pass the same values through the style props.
Long pressing a PreviewMenuTrigger measures it and the menu, then animates its content from its place on screen into a larger preview, up to 360 points wide. The preview and the menu below it are centered together between the top and bottom safe areas. The rest of the screen fades behind a scrim, and the menu grows out of the trigger into place.
The original trigger is hidden while lifted, so the preview appears to rise out of it. With custom preview content, the trigger's content cross-fades into it as it grows. Pressing outside closes the menu and the preview and menu shrink back into the trigger. Use it for photos, messages or cards that benefit from a closer look before acting.
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/interactions/preview-menu.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/interactions/preview-menu.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/interactions/preview-menu.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
Default
Web preview
This code uses Tailwind classes that need Uniwind or NativeWind. With StyleSheet, pass the same values through the style props.
Disabled item
Includes a disabled menu item.
Web preview
This code uses Tailwind classes that need Uniwind or NativeWind. With StyleSheet, pass the same values through the style props.
Custom preview
Shows custom preview content with a 4 / 3 aspect ratio.
Web preview
Custom preview open
The custom preview, open on first render.

Accessibility
- The trigger has a
longpressaccessibility action, so screen reader users can open the menu without holding. - The trigger exposes
expandedanddisabledstates. - The preview is hidden from screen readers; focus goes to the menu.
API Reference
PreviewMenu
The root that owns the open state and preview size.
| Prop | Type | Default |
|---|---|---|
open | boolean | - |
defaultOpen | boolean | - |
onOpenChange | (open: boolean) => void | - |
aspectRatio | number | - |
children | React.ReactNode | - |
Put a PreviewMenuTrigger with the element and a PreviewMenuContent with PreviewMenuItems inside PreviewMenu. The menu can be uncontrolled or controlled with open, defaultOpen and onOpenChange. Set aspectRatio to size the preview, for example 4 / 3. usePreviewMenu returns open, lifted and frame. A medium impact haptic plays when the menu opens, if the app provides an adapter through HapticsProvider.
PreviewMenuTrigger
The element that opens the preview on long press.
Also accepts the props of React.ComponentProps<typeof PreviewMenuPrimitive.Trigger>.
PreviewMenuContent
The scrim, the lifted preview and the menu.
| Prop | Type | Default |
|---|---|---|
preview | React.ReactNode | - |
previewClassName | string | - |
portalHost | string | - |
Also accepts the props of React.ComponentProps<typeof PreviewMenuPrimitive.Popup>.
By default the preview repeats the trigger's children; pass preview to show different content, such as a larger image. previewClassName styles the preview container, and portalHost names a portal host to render into. The preview stays within the top and bottom safe areas and leaves room for the measured height of the menu. Animations respect the system reduce motion setting. On iOS the content renders in a full-window overlay so it appears above native screens.
PreviewMenuItem
A menu action.
| Prop | Type | Default |
|---|---|---|
variant | "default" | "destructive" | "default" |
children | React.ReactNode | - |
Also accepts the props of React.ComponentProps<typeof PreviewMenuPrimitive.Item>.
PreviewMenuSeparator
A thick divider between groups of items.
Also accepts the props of React.ComponentProps<typeof PreviewMenuPrimitive.Separator>.
PreviewMenuItemVariant
Values: .default, .destructive.
.previewMenu
| Parameter | Type | Default |
|---|---|---|
isPresented | Binding<Bool>? | nil |
aspectRatio | CGFloat? | nil |
items | () -> Items | - |
preview | () -> Preview | - |
Overloads: previewMenu(isPresented:aspectRatio:items:), previewMenu(isPresented:aspectRatio:items:preview:).
PreviewMenuItem
A menu action.
| Parameter | Type | Default |
|---|---|---|
variant | Variant: .default | .destructive | .default |
icon | Image? | nil |
action | () -> Void | - |
label | () -> Label | - |
_ย title | LocalizedStringKey | - |
verbatim | String | - |
Overloads: init(variant:icon:action:label:), init(_:icon:variant:action:), init(verbatim:icon:variant:action:).
PreviewMenuSeparator
A thick divider between groups of items.
Takes no parameters.
PreviewMenu
The root that owns the open state and preview size.
| Parameter | Type | Default |
|---|---|---|
open | Boolean | - |
onOpenChange | (Boolean) -> Unit | - |
trigger | @Composable () -> Unit | - |
modifier | Modifier | Modifier |
preview | (@Composable () -> Unit)? | null |
aspectRatio | Float? | null |
enabled | Boolean | true |
content | @Composable ColumnScope.() -> Unit | - |
PreviewMenuItem
A menu action.
| Parameter | Type | Default |
|---|---|---|
onClick | () -> Unit | - |
modifier | Modifier | Modifier |
variant | MenuItemVariant | MenuItemVariant.Default |
enabled | Boolean | true |
content | @Composable RowScope.() -> Unit | - |
text | String | - |
icon | ImageVector? | null |
Overloads: PreviewMenuItem(onClick, content), PreviewMenuItem(text, onClick, icon).
PreviewMenuSeparator
A thick divider between groups of items.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
