# React Native Dropdown Menu

> React Native dropdown menu and context menu that drops from a button or opens on a long press: icons, descriptions, destructive, disabled and checked items, iOS, Material and web designs, or an action sheet. Pure JavaScript: works in Expo Go and on the web.

# DropdownMenu

`DropdownMenu` drops a list of actions from the button that opens it: the ⋯ on a card, a "Sort" button, a toolbar icon. Long-press instead, and it's a context menu. It takes the same `actions` as [`ActionSheet`](./action-sheet), and `presentation="sheet"` opens them as one.

It's pure JavaScript, so unlike native menus it runs in Expo Go and on the web, and looks the same as the rest of your pickers: iOS, Material or web.

```tsx
import { DropdownMenu } from 'patine-ui';
```

```tsx live
import { useState } from 'react';
import { Text, View } from 'react-native';
import { DropdownMenu } from 'patine-ui';
import { Icon } from '@patine-ui/icons';
import { DemoButton } from './DemoButton';

export default function Example() {
  const [pinned, setPinned] = useState(false);
  const [last, setLast] = useState('Nothing yet');
  return (
    <View style={{ flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between' }}>
      <Text>Last action: {last}</Text>
      <DropdownMenu
        actions={[
          { label: 'Edit', icon: <Icon name="edit" size="sm" />, onPress: () => setLast('Edit') },
          { label: 'Duplicate', icon: <Icon name="copy" size="sm" />, onPress: () => setLast('Duplicate') },
          { label: 'Pin to top', icon: <Icon name="pin" size="sm" />, selected: pinned, onPress: () => setPinned((p) => !p) },
          { label: 'Delete', icon: <Icon name="trash" size="sm" />, destructive: true, onPress: () => setLast('Delete') },
        ]}
      >
        {({ open }) => (
          <DemoButton size="icon" variant="secondary" title="⋯" accessibilityLabel="Note options" onPress={open} />
        )}
      </DropdownMenu>
    </View>
  );
}
```

## Example: a file's menu

A shared drive: each file has a menu with its own state, so Star shows a check on starred files and Delete takes the file out of the list.

```tsx live
import { useState } from 'react';
import { Button, DropdownMenu, List, ListItem, Text } from 'patine-ui';
import { Icon } from '@patine-ui/icons';

const FILES = [
  { id: 1, name: 'Roadmap 2027.pdf', meta: 'Priya · 2 MB', starred: true },
  { id: 2, name: 'Launch budget.xlsx', meta: 'You · 640 KB', starred: false },
  { id: 3, name: 'Hero shot.png', meta: 'Marco · 4.8 MB', starred: false },
];

export default function Example() {
  const [files, setFiles] = useState(FILES);
  const [last, setLast] = useState('');
  const toggleStar = (id: number) => setFiles((all) => all.map((f) => (f.id === id ? { ...f, starred: !f.starred } : f)));
  return (
    <>
      <List title="Shared with me" style={{ width: '100%', maxWidth: 440 }}>
        {files.map((file) => (
          <ListItem
            key={file.id}
            leading={<Icon name={file.starred ? 'star' : 'file'} color={file.starred ? 'warning' : 'textSecondary'} />}
            title={file.name}
            description={file.meta}
            trailing={
              <DropdownMenu
                actions={[
                  { label: 'Open', icon: <Icon name="external" size="sm" />, onPress: () => setLast(`Opened ${file.name}`) },
                  { label: 'Share', icon: <Icon name="share" size="sm" />, onPress: () => setLast(`Sharing ${file.name}`) },
                  { label: 'Download', icon: <Icon name="download" size="sm" />, onPress: () => setLast(`Downloading ${file.name}`) },
                  { label: 'Star', icon: <Icon name="star" size="sm" />, selected: file.starred, onPress: () => toggleStar(file.id) },
                  { label: 'Delete', icon: <Icon name="trash" size="sm" />, destructive: true, onPress: () => setFiles((all) => all.filter((f) => f.id !== file.id)) },
                ]}
              >
                {({ open }) => (
                  <Button size="icon" variant="ghost" accessibilityLabel={`Options for ${file.name}`} onPress={open}>
                    <Icon name="moreVertical" />
                  </Button>
                )}
              </DropdownMenu>
            }
          />
        ))}
      </List>
      {last ? <Text size="sm" color="textSecondary">{last}</Text> : null}
    </>
  );
}
```

## Actions

Each action is the same as in an [`ActionSheet`](./action-sheet#actions): `{ label, onPress, description, icon, selected, destructive, disabled, testID }`. A tap closes the menu and `onPress` runs once it has closed, so an action can open a sheet or a modal.

The iOS design puts icons after the label with a hairline between actions, as iOS menus do; Material and the web put them first.

## The trigger

`children` is the trigger. A node is wrapped in a pressable that opens the menu; name it for screen readers with `accessibilityLabel`. To use your own button, pass a function: it gets `open` and `visible`.

This one is a "Sort" button with a title, a ✓ on the current order and a line under each choice:

```tsx live
import { useState } from 'react';
import { View } from 'react-native';
import { DropdownMenu } from 'patine-ui';
import { DemoButton } from './DemoButton';

const SORTS = [
  { label: 'Relevance', description: 'Best match first' },
  { label: 'Price', description: 'Lowest first' },
  { label: 'Rating', description: 'Highest rated first' },
  { label: 'Distance', description: 'Needs your location', disabled: true },
];

export default function Example() {
  const [sort, setSort] = useState('Relevance');
  return (
    <View style={{ alignItems: 'center' }}>
      <DropdownMenu
        title="Sort results by"
        actions={SORTS.map((s) => ({ ...s, selected: s.label === sort, onPress: () => setSort(s.label) }))}
      >
        {({ open, visible }) => (
          <DemoButton size="sm" variant="secondary" title={`Sort: ${sort} ${visible ? '▴' : '▾'}`} onPress={open} />
        )}
      </DropdownMenu>
    </View>
  );
}
```

## Context menu

`openOnLongPress` opens the menu on a long press instead of a tap, as a message bubble or a photo does.

```tsx live
import { Text, View } from 'react-native';
import { DropdownMenu, useTheme } from 'patine-ui';

export default function Example() {
  const { colors } = useTheme();
  return (
    <View style={{ alignItems: 'center' }}>
      <DropdownMenu
        openOnLongPress
        accessibilityLabel="Message, long-press for options"
        actions={[
          { label: 'Reply' },
          { label: 'Copy' },
          { label: 'Forward', description: 'To a chat or a group' },
          { label: 'Delete', destructive: true },
        ]}
        styles={{
          trigger: {
            backgroundColor: colors.primary,
            paddingVertical: 10,
            paddingHorizontal: 14,
            borderRadius: 18,
            borderBottomRightRadius: 4,
          },
        }}
      >
        <Text style={{ color: colors.onPrimary, fontSize: 15 }}>Long-press me 👋</Text>
      </DropdownMenu>
    </View>
  );
}
```

## Where it opens

The menu opens under the trigger, or above it when there's more room there. `align` picks the edge it lines up with:

- `'auto'` (default): the trigger's left edge, or its right edge when the trigger sits in the right half of the window, so a ⋯ at the end of a row opens inwards.
- `'start'` / `'end'`: the trigger's start or end edge, flipped in right-to-left layouts.

`width` sets the menu's width: 250 in the iOS design and 200 otherwise.

`presentation="sheet"` opens the same actions as an [`ActionSheet`](./action-sheet) instead, from the bottom of the screen.

## Accessibility

The trigger is a button that reports whether the menu is expanded. Each action is a button named by its label and description, marked disabled or selected. A tap outside, Android's Back and Escape on the web close the menu, and on the web arrow keys move between actions.

With a mouse or trackpad (the web's `(pointer: fine)`), the menu is compact, as desktop menus are: 34 px rows, small text and a quiet caption for the `title`. Touch screens and the iOS and Android apps keep 44 pt rows. Give every action an `icon`: it sits before the label in every design except iOS, which puts it at the end.

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `actions` | `DropdownMenuAction[]` | **required** | The actions, top to bottom. Same shape as [`ActionSheetAction`](./action-sheet#props). |
| `children` | `ReactNode \| ({ open, visible }) => ReactNode` | **required** | The trigger: a node that opens the menu, or a function for your own button. |
| `title` | `string` | — | A small heading above the actions. |
| `align` | `'auto' \| 'start' \| 'end'` | `'auto'` | The trigger edge the menu lines up with. |
| `width` | `number` | `250` iOS / `200` other | The menu's width. |
| `presentation` | `'dropdown-menu' \| 'sheet'` | `'dropdown-menu'` | A menu by the trigger, or an action sheet. |
| `openOnLongPress` | `boolean` | `false` | Open on a long press, as a context menu. |
| `disabled` | `boolean` | `false` | The trigger doesn't open the menu. |
| `open` | `boolean` | — | Open, when you control it. Pair with `onOpenChange`. |
| `defaultOpen` | `boolean` | `false` | Open at first, when it keeps its own state. |
| `onOpenChange` | `(open: boolean) => void` | — | When it opens, and when it closes for any reason (before an action runs). Not called when `open` changes from your code. |
| `accessibilityLabel` | `string` | — | What screen readers call the trigger, such as 'More options'. |
| `theme` | `DeepPartial<Theme>` | — | Theme override. See [Theming](../guides/theming). |
| `design` | `'brand' \| 'ios' \| 'material' \| 'web' \| 'native'` | from `PatineProvider` | The look to follow, over the provider's: [brand, iOS, Material or web](../guides/designs), or `'native'` for the platform's own. |
| `style` | `StyleProp<ViewStyle>` | — | The box around the trigger. |
| `styles` | `SlotStyles<DropdownMenuSlot>` | — | [Slot styles](../guides/styling): `trigger` (the pressable around a node trigger), `menu`, `header`, `title`, `action`, `actionLabel`, `actionDescription`, `check`. |
| `testID` | `string` | — | On the trigger; the menu gets `${testID}-menu`. |

## Related

- [ActionSheet](./action-sheet): the same actions from the bottom of the screen
- [Select](./select): pick a value, not an action
- Migrate from [@react-native-menu/menu](../resources/migration/react-native-menu), [zeego](../resources/migration/zeego) or [react-native-popup-menu](../resources/migration/popup-menu)
