Skip to content

Menu

A list of actions that opens from a button, with keyboard navigation and nested submenus.

// Radix — @radix-ui/react-dropdown-menu
import { Menu, MenuItem, MenuSub, MenuSubContent, MenuSubTrigger, MenuTrigger } from "@shavin/ui";

Overflow menu

MenuTrigger with no children renders a three-dot button named "More options". Pass aria-label to say what it acts on. variant="danger" colours a destructive item and adds a rule above it, so put it last.

Corner Market$64.18

Nothing chosen yet

Component Source
import { Menu, MenuTrigger, MenuItem } from "@shavin/ui";

<Menu align="end" trigger={<MenuTrigger aria-label="Actions for Corner Market, $64.18" />}>
  <MenuItem onSelect={() => edit()}>Edit</MenuItem>
  <MenuItem onSelect={() => split()}>Split</MenuItem>
  <MenuItem disabled>Mark as reviewed</MenuItem>
  <MenuItem variant="danger" onSelect={() => remove()}>Delete</MenuItem>
</Menu>

Your own trigger

trigger can be any element that forwards its ref, such as Button. Menu opens on click, Enter, Space or Arrow Down.

Nothing chosen yet

Component Source
<Menu
  trigger={
    <Button variant="outline">
      Export
      <Icon name="ChevronDown" size="sm" color="inherit" />
    </Button>
  }
>
  <MenuItem onSelect={() => exportAs("csv")}>CSV</MenuItem>
  <MenuItem onSelect={() => exportAs("pdf")}>PDF statement</MenuItem>
</Menu>

Submenus

Wrap a MenuSubTrigger and a MenuSubContent in MenuSub. Arrow Right opens the submenu, Arrow Left closes it. Keep it to one level where you can.

Nothing chosen yet

Component Source
<Menu trigger={<Button variant="outline">Move to</Button>}>
  <MenuSub>
    <MenuSubTrigger>Bank accounts</MenuSubTrigger>
    <MenuSubContent>
      <MenuItem onSelect={() => move("joint-checking")}>Joint checking</MenuItem>
      <MenuItem onSelect={() => move("emergency-savings")}>Emergency savings</MenuItem>
    </MenuSubContent>
  </MenuSub>
  <MenuSub>
    <MenuSubTrigger>Cards</MenuSubTrigger>
    <MenuSubContent>
      <MenuItem onSelect={() => move("everyday-card")}>Everyday card</MenuItem>
      <MenuItem onSelect={() => move("travel-card")}>Travel card</MenuItem>
    </MenuSubContent>
  </MenuSub>
</Menu>

Menu, Dropdown or Context menu

Menu runs commands: each item does something when chosen and nothing stays selected. To pick a value that the control then shows, use Select or Dropdown. For the same kind of list opened by right-click or long-press, use ContextMenu. The list is 208px wide and scrolls after about six items.

Keyboard

KeyAction
Enter / Space / Arrow DownOn the trigger: opens the menu and focuses the first item.
Arrow Up / DownMoves between items, skipping disabled ones.
LettersJumps to the next item that starts with them.
Arrow Right / LeftOpens or closes a submenu.
Enter / SpaceChooses the focused item and closes the menu.
EscapeCloses the menu and returns focus to the trigger.

Data attributes

AttributeValues
[data-highlighted]On the item that has keyboard focus or the pointer.
[data-disabled]On a disabled item.
[data-state]"open" | "closed" on the trigger and on a MenuSubTrigger.

Props

Menu

PropTypeDefaultDescription
trigger*ReactNode—Trigger element slot.
children*ReactNode—Menu content items.
align"start" | "end"startContent alignment (start or end). Default start.
onOpenChange(open: boolean) => void—Called when the menu opens or closes (e.g. keep a hover-only trigger visible while open).
variant"default" | "danger""default"—

* required

MenuItem

PropTypeDefault
asChildboolean—
disabledboolean—
onSelect((event: Event) => void)—
textValuestring—
variant"default" | "danger" | null"default"

MenuSub

PropTypeDefault
childrenReact.ReactNode—
defaultOpenboolean—
onOpenChange((open: boolean) => void)—
openboolean—

MenuItem, MenuSub, MenuSubTrigger and MenuSubContent pass their other props to the matching Radix DropdownMenu part, so onSelect, disabled and textValue work as in Radix.

Configure Theme
Theme
Brand Color
Custom
Gray Family
Appearance
Radius
Scaling
Panel Style
Heading Font
Body Font