Menu
A dropdown list of actions opened from a button. Supports sections, submenus, and selection.
View in Storybook (opens in a new tab)
Installation
import { Menu } from "@ginga-ui/core";Basic usage
Put a Button and a Menu inside MenuTrigger. Use onAction to handle the chosen item.
import { Button, Menu, MenuItem, MenuSeparator, MenuTrigger } from "@ginga-ui/core";
import { Copy, Pencil, Trash2 } from "lucide-react";
export function BasicExample() {
return (
<MenuTrigger>
<Button variant="outline">Actions</Button>
<Menu onAction={(key) => console.log("Action:", key)}>
<MenuItem id="edit" startIcon={<Pencil />} shortcut="⌘E">
Edit
</MenuItem>
<MenuItem id="duplicate" startIcon={<Copy />} shortcut="⌘D">
Duplicate
</MenuItem>
<MenuSeparator />
<MenuItem id="delete" startIcon={<Trash2 />}>
Delete
</MenuItem>
</Menu>
</MenuTrigger>
);
}Sections
Group items with MenuSection and separate them with MenuSeparator.
import { Button, Menu, MenuItem, MenuSection, MenuSeparator, MenuTrigger } from "@ginga-ui/core";
export function SectionExample() {
return (
<MenuTrigger>
<Button variant="outline">File</Button>
<Menu>
<MenuSection title="Create">
<MenuItem id="new">New</MenuItem>
<MenuItem id="open">Open</MenuItem>
</MenuSection>
<MenuSeparator />
<MenuSection title="Export">
<MenuItem id="pdf">PDF</MenuItem>
<MenuItem id="png" disabled>
PNG
</MenuItem>
</MenuSection>
</Menu>
</MenuTrigger>
);
}Submenu
Put a MenuItem and a nested Menu inside SubmenuTrigger.
import { Button, Menu, MenuItem, MenuTrigger, SubmenuTrigger } from "@ginga-ui/core";
import { ChevronRight, Copy } from "lucide-react";
export function SubmenuExample() {
return (
<MenuTrigger>
<Button variant="outline">Share</Button>
<Menu submenuIcon={<ChevronRight />}>
<MenuItem id="copy-link">Copy link</MenuItem>
<SubmenuTrigger>
<MenuItem id="send">Send to</MenuItem>
<Menu>
<MenuItem id="mail">Email</MenuItem>
<MenuItem id="chat">Chat</MenuItem>
</Menu>
</SubmenuTrigger>
</Menu>
</MenuTrigger>
);
}Selection
Set selectionMode to show a check next to the selected items.
import { useState } from "react";
import { Button, Menu, MenuItem, MenuTrigger } from "@ginga-ui/core";
import { Check } from "lucide-react";
import type { Selection } from "react-aria-components";
export function SelectionExample() {
const [selected, setSelected] = useState<Selection>(new Set(["grid"]));
return (
<MenuTrigger>
<Button variant="outline">View</Button>
<Menu
checkIcon={<Check />}
selectionMode="single"
selectedKeys={selected}
onSelectionChange={setSelected}
>
<MenuItem id="list">List</MenuItem>
<MenuItem id="grid">Grid</MenuItem>
<MenuItem id="board">Board</MenuItem>
</Menu>
</MenuTrigger>
);
}Props
MenuTrigger
Accepts the props of React Aria's MenuTrigger (opens in a new tab).
Menu
| Name | Type | Default | Description |
|---|---|---|---|
children | ReactNode | - | MenuItem, MenuSection, MenuSeparator, and SubmenuTrigger elements. |
placement | Placement | "bottom start" | Position of the menu relative to the trigger. |
offset | number | - | Distance from the trigger in pixels. |
checkIcon | ReactNode | - | Icon shown next to selected items. A check mark is drawn when omitted. Inherited by submenus. |
submenuIcon | ReactNode | - | Icon shown at the end of items that open a submenu. A chevron is drawn when omitted. Inherited by submenus. |
Also accepts the props of React Aria's Menu (opens in a new tab).
MenuItem
| Name | Type | Default | Description |
|---|---|---|---|
disabled | boolean | false | Disables the item. |
startIcon | ReactNode | - | Icon shown before the label. |
shortcut | string | - | Keyboard shortcut shown at the end of the item. It is only displayed, not registered. |
textValue | string | children (string only) | Text used for type-to-select and screen readers. Required when children is not a string. |
Also accepts the props of React Aria's MenuItem (opens in a new tab).
MenuSection
| Name | Type | Default | Description |
|---|---|---|---|
title | ReactNode | - | Heading shown at the top of the section. |
Also accepts the props of React Aria's MenuSection (opens in a new tab).
MenuSeparator
Accepts the props of React Aria's Separator (opens in a new tab).
SubmenuTrigger
Accepts the props of React Aria's SubmenuTrigger (opens in a new tab).