Menu
"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
"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.
"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.
"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
Menu
The button that opens the menu, a Button or IconButton. Menu adds the id, popoverTarget and ARIA attributes to it.
MenuItem, MenuGroup and MenuSeparator elements.
Side of the trigger. Defaults to "bottom".
Alignment along that side. Defaults to "start".
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.
MenuItem
Icon before the label, such as <Copy />.
Visual shortcut hint at the end, such as "⌘C". Pass aria-keyshortcuts for assistive tech.
"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.
MenuGroup
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
MenuSeparator has no props of its own. It renders a <div>, forwards its ref and passes <div> attributes through.
Styling
| Hook | Values |
|---|---|
| Class | cherry-menu |
data-placement | top, bottom, left, right |
data-align | start, center, end |
| States | :popover-open |
| Parts | cherry-menu__trigger, cherry-menu__group, cherry-menu__label, cherry-menu__separator |
| Item class | cherry-menu-item |
Item data-variant | default, danger |
| Item states | aria-disabled, :hover, :focus |
| Item parts | cherry-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").