Navigation
Menu
A menu is a short list of actions that floats over the page from a button, such as a project's options: Edit project, Export payments, Leave project.
In kanso-ui as Menu
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
ButtonorIconButtonplaced directly insideMenu: the trigger. Name it well, since the menu takes its accessible name from it. - One
Menu.Contentholding the items. The menu is portalled to the end of the body, so everything it shows goes in there.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | 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'sMenuprops, such asonAction,selectionMode('single' | 'multiple'),selectedKeysanddefaultSelectedKeys.side('bottom' | 'top' | 'start' | 'end' | 'left' | 'right',startandendfollowing the writing direction),align('start' | 'center' | 'end'),sideOffsetandalignOffsetplace it; left out, a menu opens below its trigger and a submenu beside its item.searchdraws content above the items, usually aSearchField; wrap the part inAutocompleteto filter with it.renderEmptyStatereplaces the muted "No results" row an empty menu shows.containersays where to portal it.Menu.Item: one action, with anid. Its label ischildren, withleadingbefore it,trailingafter it, andshortcutat the end, drawn as a keycap and announced apart from the label. Anhrefmakes it a link.isDisabledgreys it out. An item that opens a submenu draws the chevron itself.Menu.Section: a named group of items;headernames it.Menu.Separator: a rule between groups, with 8dp either side.Menu.Submenu: exactly two children, theMenu.Itemthat opens it and theMenu.Contentit opens.delayis how long the pointer rests before it opens, 200ms by default.Menu.LoadMore: the row shown while more items load. React Aria callsonLoadMorewhen it comes into view, and draws it only whileisLoading.
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.