Skip to content

Navigation

Menu

tsx
"use client";
import { Button, Menu, MenuItem } from "@cherry-design-system/react";

export function ProjectActions() {
  return (
    <Menu trigger={<Button variant="outline">Actions</Button>}>
      <MenuItem onClick={() => console.log("rename")}>Rename</MenuItem>
      <MenuItem onClick={() => console.log("duplicate")}>Duplicate</MenuItem>
    </Menu>
  );
}

Menu is a menu button: the trigger opens a list of actions (role="menu") anchored to it, on the native popover attribute. Compose it with MenuItem, MenuGroup and MenuSeparator. For non-action content such as a form or a note, use Popover.

Examples

Groups, icons, shortcuts and a danger item

tsx
"use client";
import { Button, Menu, MenuGroup, MenuItem, MenuSeparator } from "@cherry-design-system/react";
import { Copy, Pencil, Trash } from "lucide-react";

export function ProjectMenu({ onCopy, onRename, onDelete }: {
  onCopy: () => void;
  onRename: () => void;
  onDelete: () => void;
}) {
  return (
    <Menu trigger={<Button variant="outline">Actions</Button>}>
      <MenuGroup label="Project">
        <MenuItem icon={<Copy />} shortcut="⌘C" aria-keyshortcuts="Meta+C" onClick={onCopy}>
          Copy link
        </MenuItem>
        <MenuItem icon={<Pencil />} onClick={onRename}>Rename</MenuItem>
      </MenuGroup>
      <MenuSeparator />
      <MenuItem icon={<Trash />} variant="danger" onClick={onDelete}>
        Delete project
      </MenuItem>
    </Menu>
  );
}

Icon button trigger and placement

placement picks the side of the trigger and align the alignment along it.

tsx
"use client";
import { IconButton, Menu, MenuItem } from "@cherry-design-system/react";
import { EllipsisVertical } from "lucide-react";

export function RowMenu() {
  return (
    <Menu
      placement="bottom"
      align="end"
      trigger={<IconButton aria-label="Row actions" icon={<EllipsisVertical />} variant="ghost" />}
    >
      <MenuItem>Edit</MenuItem>
      <MenuItem disabled>Archive</MenuItem>
    </Menu>
  );
}

Keeping the menu open

Choosing an item runs onClick and then closes the menu, unless onClick calls event.preventDefault(). Inside the menu, useMenu() returns { close } (or null outside a Menu) so a custom child can close it.

tsx
"use client";
import { useState } from "react";
import { MenuItem } from "@cherry-design-system/react";

export function PinItem() {
  const [pinned, setPinned] = useState(false);
  return (
    <MenuItem
      onClick={(event) => {
        event.preventDefault();
        setPinned((value) => !value);
      }}
    >
      {pinned ? "Unpin" : "Pin"}
    </MenuItem>
  );
}

Properties

triggerReactElementrequired

The button that opens the menu, a Button or IconButton. Menu adds the id, popoverTarget and ARIA attributes to it.

childrenReactNoderequired

MenuItem, MenuGroup and MenuSeparator elements.

placement"left" | "right" | "top" | "bottom"

Side of the trigger. Defaults to "bottom".

align"start" | "end" | "center"

Alignment along that side. Defaults to "start".

onOpenChange(open: boolean) => void

Called when the menu opens or closes.

Menu renders a <div> with the popover attribute next to the trigger, forwards its ref to it and passes other <div> attributes through. It is a Client Component.

iconReactNode

Icon before the label, such as <Copy />.

shortcutReactNode

Visual shortcut hint at the end, such as "⌘C". Pass aria-keyshortcuts for assistive tech.

variant"default" | "danger"

"danger" for destructive actions. Defaults to "default".

MenuItem renders a <button role="menuitem">, forwards its ref and passes other <button> attributes through. A disabled item stays visible but is skipped by the keyboard and does nothing.

labelReactNode

Small all-caps heading over the group; names it for assistive tech.

MenuGroup renders a <div role="group">, forwards its ref and passes other <div> attributes through.

MenuSeparator has no props of its own. It renders a <div>, forwards its ref and passes <div> attributes through.

Styling

HookValues
Classcherry-menu
data-placementtop, bottom, left, right
data-alignstart, center, end
States:popover-open
Partscherry-menu__trigger, cherry-menu__group, cherry-menu__label, cherry-menu__separator
Item classcherry-menu-item
Item data-variantdefault, danger
Item statesaria-disabled, :hover, :focus
Item partscherry-menu-item__icon, cherry-menu-item__label, cherry-menu-item__shortcut

The panel reads --cherry-bg-elevated, --cherry-border-default, --cherry-radius-xl and --cherry-elevation-lg. Danger items use --cherry-danger-fg and --cherry-danger-bg.

Accessibility

Opening the menu focuses the first item. Up and Down, Home and End, and typeahead move between items; Escape or Tab close it and focus returns to the trigger. Shortcut hints are hidden from screen readers. The danger tint is not announced, so name destructive items clearly ("Delete project").