# Menu

> Actions or options behind a trigger, with groups, checkable items, submenus and shortcuts.

Category: Overlays · Atomic level: molecule · Built on Base UI Menu
Page: https://ui.dtheo.dev/docs/components/menu

## Install

```bash
npx dtheo@latest add menu
# or, with the shadcn CLI
npx shadcn@latest add https://ui.dtheo.dev/r/menu.json
```

Dependencies: @base-ui/react, clsx, tailwind-merge, lucide-react. Registry dependencies: utils, select.

## Exports

`Menu`, `MenuTrigger`, `MenuContent`, `MenuItem`, `MenuCheckboxItem`, `MenuRadioGroup`, `MenuRadioItem`, `MenuGroup`, `MenuLabel`, `MenuSeparator`, `MenuShortcut`, `MenuSub`, `MenuSubTrigger`, `MenuSubContent`

## Use it for

- Row actions ("…")
- Toolbar dropdowns
- View options

## Reach for something else

- Navigation between pages: use links or the sidebar
- Choosing a value for a form: use Select or Combobox

## Keyboard

| Keys | Action |
| --- | --- |
| Arrow keys | Move the highlight; right opens a submenu |
| Enter / Space | Runs the highlighted item |
| Type a letter | Jumps to the matching item |
| Escape | Closes the menu |

## Examples

### menu

```tsx
import * as React from 'react';
import { CopyIcon, GitCompareIcon, MoreHorizontalIcon, Trash2Icon } from 'lucide-react';
import { Button } from '@/components/ui/button';
import {
  Menu,
  MenuCheckboxItem,
  MenuContent,
  MenuGroup,
  MenuItem,
  MenuLabel,
  MenuSeparator,
  MenuShortcut,
  MenuSub,
  MenuSubContent,
  MenuSubTrigger,
  MenuTrigger,
} from '@/components/ui/menu';
import { useToast } from '@/components/ui/toast';

const baselines = ['R-0411 · Previous run', 'R-0398 · Accepted baseline', 'Reference model'];

export default function MenuExample() {
  const toast = useToast();
  const [showLimit, setShowLimit] = React.useState(true);
  const [showBand, setShowBand] = React.useState(false);
  return (
    <div className="flex w-full max-w-sm items-center gap-3 rounded-card border border-border bg-card py-1.5 pr-1.5 pl-3">
      <div className="flex min-w-0 flex-1 flex-col">
        <span className="truncate text-body font-medium">R-0412 · High-gain step</span>
        <span className="truncate text-caption text-muted-foreground">Bench 3 · overshoot 17.6 %</span>
      </div>
      <Menu>
        <MenuTrigger render={<Button variant="ghost" size="icon" aria-label="Actions for R-0412" />}>
          <MoreHorizontalIcon aria-hidden="true" />
        </MenuTrigger>
        <MenuContent align="end" className="min-w-52">
          <MenuItem
            onClick={() =>
              toast.add({ title: 'R-0413 created', description: 'Copy of R-0412, ready to retune.' })
            }
          >
            <CopyIcon aria-hidden="true" />
            Duplicate as retune
            <MenuShortcut>⇧⌘D</MenuShortcut>
          </MenuItem>
          <MenuSub>
            <MenuSubTrigger>
              <GitCompareIcon className="text-muted-foreground" aria-hidden="true" />
              Compare with
            </MenuSubTrigger>
            <MenuSubContent>
              {baselines.map((b) => (
                <MenuItem
                  key={b}
                  onClick={() => toast.add({ title: `Comparing R-0412 with ${b.split(' · ')[0]}` })}
                >
                  {b}
                </MenuItem>
              ))}
            </MenuSubContent>
          </MenuSub>
          <MenuSeparator />
          <MenuGroup>
            <MenuLabel>Show on chart</MenuLabel>
            <MenuCheckboxItem checked={showLimit} onCheckedChange={setShowLimit}>
              Torque limit, 12 N·m
            </MenuCheckboxItem>
            <MenuCheckboxItem checked={showBand} onCheckedChange={setShowBand}>
              ±2 % settling band
            </MenuCheckboxItem>
          </MenuGroup>
          <MenuSeparator />
          <MenuItem variant="destructive">
            <Trash2Icon aria-hidden="true" />
            Delete run…
          </MenuItem>
        </MenuContent>
      </Menu>
    </div>
  );
}
```

## Used in

- Run review (page): https://ui.dtheo.dev/examples/run-review
- Data table pattern (template): https://ui.dtheo.dev/docs/patterns/data-table
