Skip to content
Paste
UX Platform
Change the site theme
GitHub

Menu

A menu presents a list of menu items that a user can choose to perform an action with.

Status
alpha
Version
7.0.0
Sources
Import from
@twilio-paste/core/menu — or — @twilio-paste/menu

Using alpha components in your product

Alpha components are ready for you to use in production. Components such as Menu are likely to not see any API changes. This is only an alpha due to the lack of documentation and minimal design. Feel free to share your experience using this component at #help-design-system or start a discussion on GitHub.

Guidelines#

About Menu#

A menu presents a list of menu items that a user can choose to perform an action with. This component includes a menu trigger (a button in our case) and a menu comprising of menu items that are shown upon actioning the trigger. A menu item can be used to perform an action, a page navigation or show a sub menu.

Each menu item can only perform a single action.

Do not nest multiple actions within a menu item

Please do not add additional actionable elements inside a menu item. They will not be keyboard accessible.

Examples#

Basic menu#

Use MenuGroups to create hierarchy or logical groupings within longer menus. MenuGroups have a visible group label that should describe the grouping clearly. They can be given a prefix icon; please only use icons in a decorative manner and make the label descriptive standalone.

Add separators between MenuGroups and other menu items.

Choosing a menu trigger#

The MenuButton is the standard Paste Button with some extra functionality. As a result it takes all the usual props the Paste Button takes, meaning you have full access to all the variants and styling options.

For example, you can create an icon button menu trigger like so:

Composition notes#

Performing actions#

A menu item can perform 2 basic tasks:

  • trigger an action (switching a view between grid and list)
  • trigger a page navigation (going to a new page)

To do so, either set href with a valid url to go to a new page, or set the onClick as an event handler on the MenuItem.

Composing menu items#

Note

Menu item content is composible however you want. We'll have more complete best practice guidelines soon, but in the meantime here are some example compositions using Paste components.

Anatomy#

See the button component.

PropertyDefault tokenModifiable?
background-colorcolor-background-bodyNo
border-widthborder-width-10No
border-colorcolor-border-lightNo
border-radiusborder-radius-20No
box-shadowshadowNo
max-widthsize-30No
min-widthsize-20No
padding-topspace-30No
padding-bottomspace-30No
z-indexz-index-20No

Default#

PropertyDefault tokenModifiable?
colorcolor-text (default) color-text-weaker (disabled)No
padding-topspace-30No
padding-bottomspace-30No
padding-leftspace-90 (in-group) or space-70 (regular)No
padding-rightspace-90 (in-group) or space-70 (regular)No

Hover & focused#

PropertyDefault tokenModifiable?
colorcolor-text-linkNo
PropertyDefault tokenModifiable?
padding-topspace-30No
padding-bottomspace-30No
padding-leftspace-70No
padding-rightspace-70No
colorcolor-textNo
font-weightfont-weight-boldNo

See the separator component.

PropertyDefault tokenModifiable?
padding-topspace-40No
padding-bottomspace-40No

Usage Guide#

API#

Installation#

yarn add @twilio-paste/menu - or - yarn add @twilio-paste/core

Usage#

import {Menu, MenuButton, MenuItem, MenuSeparator, useMenuState} from '@twilio-paste/menu';
import {ChevronDownIcon} from '@twilio-paste/icons/esm/ChevronDownIcon';
const PreferencesMenu = () => {
const menu = useMenuState();
return (
<>
<MenuButton {...menu} variant="primary">
Preferences <ChevronDownIcon decorative />
</MenuButton>
<Menu {...menu} aria-label="Preferences">
<MenuItem {...menu}>Settings</MenuItem>
<MenuItem {...menu} disabled>
Extensions
</MenuItem>
<MenuSeparator {...menu} />
<MenuItem {...menu}>Keyboard shortcuts</MenuItem>
</Menu>
</>
);
};

Props#

useMenuState#

Pass these as part of an object to the useMenuState hook.

PropTypeDescriptionDefault
baseIdstringID that will serve as a base for all the items IDs.
rtlboolean
orientationhorizontal, vertical, undefined
currentIdstring, null, undefinedThe current focused item id.
loopboolean, horizontal, vertical
wrapboolean, horizontal, vertical
visiblebooleanWhether it's visible or not.
animatednumber, boolean
placementauto-start, auto, auto-end, top-start, top, top-end, right-start, right, right-end, bottom-end, bottom, bottom-start, left-end, left, left-start
gutternumber, undefinedOffset between the reference and the popover on the main axis. Should not be combined with unstable_offset.
useMenuState returned props#

These props are returned by the state hook. You can spread them into this component ({...state}) or pass them separately. You can also provide these props from your own state logic.

PropTypeDescriptionDefault
baseIdstringID that will serve as a base for all the items IDs.
baseIdstringID that will serve as a base for all the items IDs.
visiblebooleanWhether it's visible or not.
animatednumber | boolean
modalbooleanToggles Dialog's modal state.
animatingbooleanWhether it's animating or not.
stopAnimation() => voidStops animation. It's called automatically if there's a CSS transition.
hide() => voidChanges the visible state to false
placement"auto-start" | "auto" | "auto-end" | "top-start...Actual placement.
orientation"horizontal" | "vertical" | undefinedDefines the orientation of the composite widget.
currentIdstring | null | undefinedThe current focused item id.
wrapboolean | "horizontal" | "vertical"If enabled, moving to the next item from the last one in a row or column will focus the first item in the next row or column and vice-versa.
groupsGroup[]Lists all the composite groups with their id and DOM ref.
itemsItem[]Lists all the composite items with their id, DOM ref, disabled state and groupId if any.
setCurrentId(value: SetStateAction<string | null | undefine...Sets currentId.
first() => voidMoves focus to the first item.
last() => voidMoves focus to the last item.
move(id: string | null) => voidMoves focus to a given item ID.
next(unstable_allTheWay?: boolean | undefined) => voidMoves focus to the next item.
previous(unstable_allTheWay?: boolean | undefined) => voidMoves focus to the previous item.
PropTypeDescriptionDefault
hideOnClickOutsideboolean, undefinedWhen enabled, user can hide the dialog by clicking outside it.
disabledboolean, undefinedSame as the HTML attribute.
PropTypeDescriptionDefault
sizestring, number, undefined
PropTypeDescriptionDefault
disabledboolean, undefinedSame as the HTML attribute.
PropTypeDescriptionDefault
disabledboolean, undefinedSame as the HTML attribute.
PropTypeDescriptionDefault
labelstringNames the grouping
iconReact.ReactNodeOne of our icon components. Must be decorative.
PropTypeDescriptionDefault
disabledboolean, undefinedSame as the HTML attribute.
idstring, undefinedSame as the HTML attribute.
onClick() => voidSame as the HTML attribute.
hrefstring, undefinedSame as the HTML attribute.
PropTypeDescriptionDefault
disabledboolean, undefinedSame as the HTML attribute.
valuestring, number, undefinedCheckbox's value is going to be used when multiple checkboxes share the same state. Checking a checkbox with value will add it to the state array.
checkedboolean, undefinedCheckbox's checked state. If present, it's used instead of state.
idstring, undefinedSame as the HTML attribute.
namestringMenuItemCheckbox's name as in menu.values.
PropTypeDescriptionDefault
disabledboolean, undefinedSame as the HTML attribute.
valuestring, number, undefinedCheckbox's value is going to be used when multiple checkboxes share the same state. Checking a checkbox with value will add it to the state array.
checkedboolean, undefinedCheckbox's checked state. If present, it's used instead of state.
idstring, undefinedSame as the HTML attribute.
namestringMenuItemRadio's name as in menu.values.

Black lives matter.