# Long press menu

Press and hold a message for its actions: it sinks, pops, lifts above a blurred screen, and the menu opens beside it.

> chatcn Pro: needs a Pro license (https://chatcn.dev/pro). Install from the `@chatcn-pro` registry with your license token; setup at https://chatcn.dev/docs/chatcn-pro.

Example: Long press menu. Press and hold any message, or right click it, for its actions. Preview: https://chatcn.dev/preview/long-press-menu-demo

## Installation

```bash
npx shadcn@latest add @chatcn-pro/long-press-menu
```

## Usage

```tsx
import { LongPressMenu } from "@/components/ui/chatcn/pro/long-press-menu"

<div data-long-press-root className="relative h-dvh">   {/* the screen the menu covers */}
  <LongPressMenu
    label="Message actions"
    align="end"
    actions={[
      { id: "copy", label: "Copy", icon: <CopyIcon />, onAction: copy },
      { id: "edit", label: "Edit", icon: <PencilIcon />, onAction: edit },
      { id: "delete", label: "Delete", icon: <TrashIcon />, destructive: true, onAction: remove },
    ]}
  >
    <MessageBubble />
  </LongPressMenu>
</div>
```

Hold for 450 ms (`delay`): the message sinks slightly while held, then pops with a short vibration where the device has one. The screen behind blurs and the message lifts out above a menu; if it is near the bottom it moves up so the menu fits, and a tall message gets the menu above it. Moving more than 8 px cancels the hold, so scrolling a long chat never opens it, and the release after a hold is not counted as a tap. Right click, the context menu key, Shift F10 or Enter on the focused message open the same menu. Destructive actions sit last, in red, after a line. The overlay covers the nearest `[data-long-press-root]`, measured in its own pixels, so it lines up inside a scaled phone frame.

## Examples

### States

Example: States. A message near the bottom of the screen lifts so the menu fits. Preview: https://chatcn.dev/preview/long-press-menu-states

## Props

| Prop | Type | Notes |
| --- | --- | --- |
| `actions` | `LongPressAction[]` | `{ id, label, icon?, destructive?, disabled?, onAction }` |
| `delay` | `number` | Hold time in ms. Default 450 |
| `label` | `string` | The menu's name |
| `align` | `"start" | "end"` | Which edge the menu lines up with |
| `disabled` | `boolean` | No menu |

## Keyboard

| Key | Action |
| --- | --- |
| Enter, Space, context menu key, Shift F10 | Open the menu |
| Arrow up, down, Home, End | Move through the actions, skipping disabled ones |
| Enter | Run the action |
| Escape, Tab | Close; focus returns to the message |

## Accessibility

- The message is a button that reports it opens a menu and whether it is open.
- The menu is a labelled menu of menu items; the lifted copy of the message is hidden from screen readers.
- Disabled actions say so and are skipped by the arrow keys.

## Motion

The message sinks to 97% over the hold, lifts on a critically damped spring over 420 ms, and the menu fades and sharpens in over 260 ms. Closing reverses it in 240 ms. Under reduced motion it opens and closes in place.

Source: https://chatcn.dev/docs/components/long-press-menu