

<InteractiveDemo
  name="menu"
  controls="[
  {
    type: &#x22;enum&#x22;,
    name: &#x22;placement&#x22;,
    options: [&#x22;bottom&#x22;, &#x22;top&#x22;, &#x22;left&#x22;, &#x22;right&#x22;],
    defaultValue: &#x22;bottom&#x22;,
  },
]"
/>

## Installation [#installation]

<InstallPrerequisite>
  Before adding components, init your project with your design system from the [Studio](/studio).
</InstallPrerequisite>

<CodeBlockTabs defaultValue="npm" groupId="package-manager">
  <CodeBlockTabsList>
    <CodeBlockTabsTrigger value="npm">
      npm
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="pnpm">
      pnpm
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="yarn">
      yarn
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="bun">
      bun
    </CodeBlockTabsTrigger>
  </CodeBlockTabsList>

  <CodeBlockTab value="npm">
    ```bash
    npx shadcn@latest add @dotui/menu
    ```
  </CodeBlockTab>

  <CodeBlockTab value="pnpm">
    ```bash
    pnpm dlx shadcn@latest add @dotui/menu
    ```
  </CodeBlockTab>

  <CodeBlockTab value="yarn">
    ```bash
    yarn dlx shadcn@latest add @dotui/menu
    ```
  </CodeBlockTab>

  <CodeBlockTab value="bun">
    ```bash
    bunx shadcn@latest add @dotui/menu
    ```
  </CodeBlockTab>
</CodeBlockTabs>

## Usage [#usage]

```tsx
import { Button } from "@/components/ui/button"
import { Menu, MenuContent, MenuItem } from "@/components/ui/menu"
import { Popover } from "@/components/ui/popover"
```

```tsx
<Menu>
  <Button>Open Menu</Button>
  <Popover>
    <MenuContent>
      <MenuItem>Edit</MenuItem>
      <MenuItem>Duplicate</MenuItem>
      <MenuItem>Delete</MenuItem>
    </MenuContent>
  </Popover>
</Menu>
```

## Anatomy [#anatomy]

A `Menu` links a trigger (`Button`) to an overlay (`Popover`) that wraps the `MenuContent`. Each `MenuItem` auto-wraps string children in a `MenuItemLabel`; add a `MenuItemDescription` for secondary text, group items with `MenuSection` + `MenuSectionHeader`, and nest a submenu with `MenuSub`.

```tsx
import { Button } from "@/components/ui/button"
import {
  Menu,
  MenuContent,
  MenuItem,
  MenuItemLabel,
  MenuItemDescription,
  MenuSection,
  MenuSectionHeader,
  MenuSub,
} from "@/components/ui/menu"
import { Popover } from "@/components/ui/popover"
```

```tsx
<Menu>
  <Button>Open Menu</Button>
  <Popover>
    <MenuContent>
      <MenuItem>
        <MenuItemLabel>Label</MenuItemLabel>
        <MenuItemDescription>Description</MenuItemDescription>
      </MenuItem>
      <MenuSection>
        <MenuSectionHeader>Section</MenuSectionHeader>
        <MenuItem>Item</MenuItem>
      </MenuSection>
      <MenuSub>
        <MenuItem>Submenu</MenuItem>
        <Popover>
          <MenuContent>
            <MenuItem>Nested item</MenuItem>
          </MenuContent>
        </Popover>
      </MenuSub>
    </MenuContent>
  </Popover>
</Menu>
```

## Triggers [#triggers]

Menus open on press by default. Set `trigger="longPress"` when press is reserved for a primary action — the menu then opens on long press (or <kbd>Alt</kbd> + <kbd>▼</kbd>):

```tsx
<Menu trigger="longPress">
  <Button onPress={crop}>Crop</Button>
  <Popover>{/* ... */}</Popover>
</Menu>
```

Set `trigger="contextMenu"` to open the menu at the pointer on right click, long press on touch, or OS keyboard shortcuts. The trigger doesn't have to be a `Button` — wrap any focusable element in React Aria's `Pressable`.

<Demo name="menu/demos/context-menu" />

```tsx
import { Pressable } from "react-aria-components"
```

```tsx
<Menu trigger="contextMenu">
  <Pressable>
    <div role="button" tabIndex={0}>
      Right click me
    </div>
  </Pressable>
  <Popover>{/* ... */}</Popover>
</Menu>
```

## Selection [#selection]

Set `selectionMode` to `single` or `multiple` on `MenuContent` to turn items into checkbox or radio items. Control the selection with `selectedKeys`/`onSelectionChange` (or `defaultSelectedKeys`), and disable specific items with `disabledKeys`.

```tsx
<MenuContent selectionMode="single" disabledKeys={["right"]}>
  <MenuItem id="top">Top</MenuItem>
  <MenuItem id="bottom">Bottom</MenuItem>
  <MenuItem id="right">Right</MenuItem>
</MenuContent>
```

## Links [#links]

Pass `href` to a `MenuItem` to render it as an `<a>`; add `target` for the link target. To route through your app router, override `MenuItem`'s `render` the way [Breadcrumbs](/docs/components/breadcrumbs#framework-setup) does for `BreadcrumbLink`.

```tsx
<MenuItem href="https://twitter.com/mehdibha" target="_blank">
  X
</MenuItem>
```

## Examples [#examples]

<Examples className="md:grid-cols-2">
  <Example name="menu/demos/basic" title="Basic Menu" />

  <Example name="menu/demos/with-avatar" title="Account Dropdown" />

  <Example name="menu/demos/with-destructive" title="Menu with Actions" />

  <Example name="menu/demos/with-icons" title="Menu with Icons" />

  <Example name="menu/demos/link-items" title="Link Items" />

  <Example name="menu/demos/checkboxes-with-icons" title="Notification Preferences" />

  <Example name="menu/demos/radio-with-icons" title="Payment Method Selector" />

  <Example name="menu/demos/complex" title="Complex Menu" />

  <Example name="menu/demos/with-sheet" title="Menu in Sheet" />

  <Example name="menu/demos/with-modal" title="Menu in Modal" />

  <Example name="menu/demos/in-dialog" title="Menu in Dialog" />
</Examples>

## API Reference [#api-reference]

### Menu [#menu]

<Reference name="menu" />

### MenuContent [#menucontent]

<Reference name="menu-content" />

### MenuItem [#menuitem]

<Reference name="menu-item" />

### MenuItemLabel [#menuitemlabel]

<Reference name="menu-item-label" />

### MenuItemDescription [#menuitemdescription]

<Reference name="menu-item-description" />

### MenuSection [#menusection]

<Reference name="menu-section" />

### MenuSectionHeader [#menusectionheader]

<Reference name="menu-section-header" />

### MenuSub [#menusub]

<Reference name="menu-sub" />
