Web and native

Menu in kanso-ui 0.59.0, for React.

import { Menu } from '@kanso-labs/kanso-ui'

A list of actions opened from a button.

It follows the Material Design menu: a surface between 112 and 280 wide with a 4dp corner, holding 48dp rows with label-large text, and a selected row in tertiary container with a check beside its label. Its container is the Expressive column's surface container low rather than the baseline's surface container.

What you provide

  • A Button or IconButton placed directly inside Menu: the trigger. Name it well, since the menu takes its accessible name from it.
  • One Menu.Content holding the items. The menu is portalled to the end of the body, so everything it shows goes in there.

Props

PropTypeDefaultDescription
childrenReactNode—The trigger, then the `Menu.Content` it opens.

Also takes the props of Omit<MenuTriggerProps, 'children'>.

Parts

  • Menu.Content: the menu and its surface. Takes React Aria's Menu props, such as onAction, selectionMode ('single' | 'multiple'), selectedKeys and defaultSelectedKeys. side ('bottom' | 'top' | 'start' | 'end' | 'left' | 'right', start and end following the writing direction), align ('start' | 'center' | 'end'), sideOffset and alignOffset place it; left out, a menu opens below its trigger and a submenu beside its item. search draws content above the items, usually a SearchField; wrap the part in Autocomplete to filter with it. renderEmptyState replaces the muted "No results" row an empty menu shows. container says where to portal it.
  • Menu.Item: one action, with an id. Its label is children, with leading before it, trailing after it, and shortcut at the end, drawn as a keycap and announced apart from the label. An href makes it a link. isDisabled greys it out. An item that opens a submenu draws the chevron itself.
  • Menu.Section: a named group of items; header names it.
  • Menu.Separator: a rule between groups, with 8dp either side.
  • Menu.Submenu: exactly two children, the Menu.Item that opens it and the Menu.Content it opens. delay is how long the pointer rests before it opens, 200ms by default.
  • Menu.LoadMore: the row shown while more items load. React Aria calls onLoadMore when it comes into view, and draws it only while isLoading.

Example

import { Button, Keycap, Menu } from '@kanso-labs/kanso-ui'

<Menu>
  <Button variant="outlined">Actions</Button>
  <Menu.Content>
    <Menu.Item id="cut" shortcut={<Keycap>⌘X</Keycap>}>Cut</Menu.Item>
    <Menu.Item id="copy" shortcut={<Keycap>⌘C</Keycap>}>Copy</Menu.Item>
    <Menu.Separator />
    <Menu.Item id="delete" isDisabled>Delete</Menu.Item>
  </Menu.Content>
</Menu>

The design’s classes

k-menu, k-menu__item, k-menu__item--critical, k-menu__shortcut and k-menu__sep. Items are <button>s; the preview resets their border, background and width until k-menu__item does it. In kanso-ui and react-native-kanso-ui it is Menu.