Long Press Menu
A React Native menu that springs out from a trigger you press and hold, with every item also exposed as an accessibility action.
Press and hold a trigger to open a menu beside it. The trigger shrinks a little under your finger, the menu springs out from its corner, and choosing an item, tapping elsewhere or pressing Escape folds it away. Every item is also an accessibility action on the trigger, so nothing depends on the long press. Built for React Native and Expo with react-native only; this page previews it in the browser through react-native-web.
Installation
CLI
npx @modus-ui/cli add long-press-menuManual
- Copy the code from the component tab.
- Create a file at
components/ui/long-press-menu.tsx. - Paste the code.
It needs no packages beyond react-native, which your Expo or React Native app already has.
Usage
On iOS and Android the menu opens in a transparent Modal, so a tap anywhere on the screen closes it. On the web it renders inline, which keeps it inside the page area you place it in.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
items | LongPressMenuItem[] | - | The menu entries. Each has a label, an onPress and an optional destructive. |
delay | number | 350 | How long to hold, in milliseconds. |
placement | "below" | "above" | "below" | Which side of the trigger the menu opens on. |
colors | Partial<LongPressMenuColors> | - | Overrides menu, text, destructive and border. |
style | StyleProp<ViewStyle> | - | Style for the wrapper around the trigger. |
Comments