Skip to content
SENVENLI UI

Menu

A list of actions under a button, with sections, icons, shortcuts and disabled items that say why.
Actions for a row
import {
  Menu,
  MenuItem,
  MenuSection,
  MenuSubmenu,
  MenuSeparator,
} from "@senvenli/react/overlay";

Examples

Sections, shortcuts and a disabled item

Titled groups; a disabled item says why.

Holding a choice

A selection mode adds checkmarks: a view option that stays set.

Composed from parts

`MenuItem`, `MenuSection`, `MenuSubmenu` and `MenuSeparator` as children; an item's label can hold more than text.

With a submenu

An item with children opens a second level on hover and the arrow key.

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

KeysWhat happens
Arrow keysMoves between items.
TypingJumps to an item.
Home, EndGoes 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

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 items: MenuItem, MenuSection, MenuSubmenu and MenuSeparator, in the order given (put the destructive item last yourself; with items the menu moves it there).

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

auto (follow the device), reduce or none, for this component; the provider's setting otherwise.

MenuItem

idRequired
Key
childrenRequired
React.ReactNode

The label: a verb ("Edit"). It may hold more than text (an avatar, two lines); then give textValue.

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"

danger for the destructive action; put it last, after a MenuSeparator.

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.

MenuSection

id
Key
titleRequired
string

The section's title ("Share"); it names the group.

childrenRequired
React.ReactNode

MenuItems and MenuSubmenus.

MenuSubmenu

idRequired
Key
lang
string

The language of the label, when it differs from the page.

isDisabled
boolean
icon
IconName
shortcut
string

Shown in mono at the end ("E").

labelRequired
string

The item that opens the submenu ("Move to").

childrenRequired
React.ReactNode

The submenu's MenuItems.