import { Button } from "@senvenli/react/action";
import { Menu, toast } from "@senvenli/react/overlay";
export default function Example() {
return (
<Menu
aria-label="Actions for order ORD-1040"
trigger={<Button variant="subtle" iconOnly iconBefore="ellipsis" aria-label="More actions" />}
onAction={(id) => toast(`Action: ${id}`)}
items={[
{ id: "edit", label: "Edit", icon: "pencil" },
{ id: "duplicate", label: "Duplicate", icon: "copy" },
{ id: "archive", label: "Archive", icon: "archive" },
{ id: "delete", label: "Delete", icon: "trash-2", tone: "danger" },
]}
/>
);
}import {
Menu,
MenuItem,
MenuSection,
MenuSubmenu,
MenuSeparator,
} from "@senvenli/react/overlay";Examples
Sections, shortcuts and a disabled item
Titled groups; a disabled item says why.import { Button } from "@senvenli/react/action";
import { Menu } from "@senvenli/react/overlay";
export default function Example() {
return (
<Menu
placement="bottom start"
trigger={<Button iconAfter="chevron-down">Invoice</Button>}
items={[
{
id: "edit",
title: "Edit",
items: [
{ id: "rename", label: "Rename", icon: "pencil", shortcut: "R" },
{ id: "duplicate", label: "Duplicate", icon: "copy", shortcut: "D" },
],
},
{
id: "share",
title: "Share",
items: [
{ id: "download", label: "Download PDF", icon: "download" },
{ id: "send", label: "Send invoice (payment pending)", icon: "send", isDisabled: true },
],
},
]}
/>
);
}Holding a choice
A selection mode adds checkmarks: a view option that stays set.import { Button } from "@senvenli/react/action";
import { Menu } from "@senvenli/react/overlay";
export default function Example() {
return (
<Menu
aria-label="Row density"
placement="bottom start"
trigger={<Button iconBefore="rows-3">Density</Button>}
selectionMode="single"
defaultSelectedKeys={["comfortable"]}
items={[
{ id: "compact", label: "Compact" },
{ id: "comfortable", label: "Comfortable" },
{ id: "spacious", label: "Spacious" },
]}
/>
);
}Composed from parts
`MenuItem`, `MenuSection`, `MenuSubmenu` and `MenuSeparator` as children; an item's label can hold more than text.import { Button } from "@senvenli/react/action";
import { Avatar } from "@senvenli/react/display";
import { Menu, MenuItem, MenuSection, MenuSeparator, MenuSubmenu } from "@senvenli/react/overlay";
export default function Example() {
return (
<Menu trigger={<Button iconBefore="user">Account</Button>} aria-label="Account">
<MenuItem id="profile" textValue="Sofia Marin">
<span className="flex items-center gap-ds-100">
<Avatar name="Sofia Marin" src="/avatars/05.webp" size="small" />
<span className="flex flex-col">
<span className="text-ds-text">Sofia Marin</span>
<span className="text-body-small text-ds-text-subtle">sofia@example.com</span>
</span>
</span>
</MenuItem>
<MenuSeparator />
<MenuSection title="Workspace">
<MenuItem id="settings" icon="settings" shortcut="⌘,">
Settings
</MenuItem>
<MenuSubmenu id="switch" label="Switch workspace" icon="arrow-left-right">
<MenuItem id="acme">Acme</MenuItem>
<MenuItem id="globex">Globex</MenuItem>
</MenuSubmenu>
</MenuSection>
<MenuSeparator />
<MenuItem id="sign-out" icon="log-out" tone="danger">
Sign out
</MenuItem>
</Menu>
);
}Guidelines
When to use it
- Several actions for one object that don't all fit as buttons.
Use something else when
- The actions belong to what is under the pointer. Context menu
- People pick a value, not run an action. Select
- Two or three actions that fit as visible buttons. Button group
Do and avoid
- Items are verbs; a disabled item says why.
Accessibility
Keyboard
| Keys | What happens |
|---|---|
| Arrow keys | Moves between items. |
| Typing | Jumps to an item. |
| Home, End | Goes to the first or last item. |
Built in
- Announced as a menu button and menu.
You provide
- A name for an icon-only menu button.
- With children: a textValue on a MenuItem whose label is not plain text, so typing can jump to it; the destructive item last, after a MenuSeparator.
API reference
Menu
| Prop | Type | Default | Description |
|---|---|---|---|
triggerRequired | ReactElement<unknown, string | JSXElementConstructor<any>> | – | The pressable that opens it: the row "…" button, the account button. |
items | readonly MenuEntry[] | – | Items, or sections of items with a title. Leave it out to compose the menu as children instead. |
children | React.ReactNode | – | With no |
onAction | (id: Key) => void | – | |
disabledKeys | Iterable<Key> | – | |
placement | Placement | – | "bottom end" by default: under the trigger, aligned to its inline end, as row menus sit. |
selectionMode | "none" | "single" | "multiple" | – | For menus that also hold a choice (a view option): checkmarks on the selected items. |
selectedKeys | Iterable<Key> | – | |
defaultSelectedKeys | Iterable<Key> | – | |
onSelectionChange | (keys: Selection) => void | – | |
isOpen | boolean | – | |
onOpenChange | (isOpen: boolean) => void | – | |
aria-label | string | – | Names the menu when the trigger's own name is not enough. |
motion | ComponentMotion | – |
|
triggerRequiredReactElement<unknown, string | JSXElementConstructor<any>>The pressable that opens it: the row "…" button, the account button.
itemsreadonly MenuEntry[]Items, or sections of items with a title. Leave it out to compose the menu as children instead.
childrenReact.ReactNodeWith no
items:MenuItem,MenuSection,MenuSubmenuandMenuSeparator, in the order given (put the destructive item last yourself; withitemsthe menu moves it there).onAction(id: Key) => voiddisabledKeysIterable<Key>placementPlacement"bottom end" by default: under the trigger, aligned to its inline end, as row menus sit.
selectionMode"none" | "single" | "multiple"For menus that also hold a choice (a view option): checkmarks on the selected items.
selectedKeysIterable<Key>defaultSelectedKeysIterable<Key>onSelectionChange(keys: Selection) => voidisOpenbooleanonOpenChange(isOpen: boolean) => voidaria-labelstringNames the menu when the trigger's own name is not enough.
motionComponentMotionauto(follow the device),reduceornone, for this component; the provider's setting otherwise.
MenuItem
| Prop | Type | Default | Description |
|---|---|---|---|
idRequired | Key | – | |
childrenRequired | React.ReactNode | – | The label: a verb ("Edit"). It may hold more than text (an avatar, two lines); then give |
textValue | string | – | The words typing jumps to; the label itself when it is plain text. |
icon | IconName | – | |
shortcut | string | – | Shown in mono at the end ("E"). |
isDisabled | boolean | – | |
tone | "danger" | – |
|
href | string | – | Makes the item a link; it goes through the host router. |
lang | string | – | The language of the label, when it differs from the page. |
idRequiredKeychildrenRequiredReact.ReactNodeThe label: a verb ("Edit"). It may hold more than text (an avatar, two lines); then give
textValue.textValuestringThe words typing jumps to; the label itself when it is plain text.
iconIconNameshortcutstringShown in mono at the end ("E").
isDisabledbooleantone"danger"dangerfor the destructive action; put it last, after aMenuSeparator.hrefstringMakes the item a link; it goes through the host router.
langstringThe language of the label, when it differs from the page.
MenuSection
| Prop | Type | Default | Description |
|---|---|---|---|
id | Key | – | |
titleRequired | string | – | The section's title ("Share"); it names the group. |
childrenRequired | React.ReactNode | – |
|
idKeytitleRequiredstringThe section's title ("Share"); it names the group.
childrenRequiredReact.ReactNodeMenuItems andMenuSubmenus.