ui-kit0.0

Overlays

Context menu

Right-click actions next to the object.

Usage

Wrap an area in ContextMenuTrigger and describe the actions in ContextMenuContent. The menu opens at the pointer on right-click, on a long press (500ms) on touch, and from the keyboard with Shift + F10 or the ContextMenu key. Items, labels, separators, checkbox and radio items and submenus are the dropdown menu's own parts under a ContextMenu name.

Quarterly report.pdf

2.4 MB · Edited 2 days ago

Brand guidelines.fig

18.7 MB · Edited 3 weeks ago

Invoice 0042.pdf

184 KB · Edited 1 November

Right-click a file (long-press on touch)

When to use

  • Shortcuts to actions on an object that already has a visible way to reach them (rows, cards, canvas items).
  • Never the only way to do something: touch and keyboard users must be able to reach the same actions from a visible control.

Not for: the primary actions of a screen (use buttons), or a menu opened from a button (use the dropdown menu).

API

ContextMenu

PropTypeDefaultDescription
openboolean—Controlled open state.
defaultOpenbooleanfalseInitial state when uncontrolled.
onOpenChange(open: boolean) => void—Called when the menu asks to open or close.

ContextMenuTrigger

PropTypeDefaultDescription
asChildboolean—Use your own element as the area.
disabledboolean—Let the browser show its own context menu.
longPressDelaynumber500Touch long-press time, ms.
tabIndexnumber0The area must be focusable for the keyboard shortcut.

ContextMenuContent

PropTypeDefaultDescription
placement'bottom-start' | …'bottom-start'Side and alignment against the pointer; flips and shifts to stay on screen.
offsetnumber2Gap to the pointer, px.

Also: ContextMenuItem (icon, shortcut, variant, disabled, onSelect), ContextMenuCheckboxItem, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuLabel, ContextMenuSeparator, ContextMenuGroup, ContextMenuSub, ContextMenuSubTrigger and ContextMenuSubContent. They take the same props as their DropdownMenu counterparts.

Keyboard

KeyAction
Shift + F10 / ContextMenuOn the area: opens the menu with the first item focused.
↓ / ↑Next / previous item (wraps around).
Home / EndFirst / last item.
A–ZTypeahead: jumps to the item that starts with what you type.
Enter / SpaceChooses the item.
→ / ←Opens / closes a submenu.
EscCloses the menu and returns focus to the area.
TabCloses the menu.

Accessibility

  • role="menu" with menuitem, menuitemcheckbox and menuitemradio items, the same as the dropdown menu.
  • The trigger area is focusable so the keyboard can reach the menu; a menu opened with the keyboard lands on its first item.
  • Focus returns to the area on close, except after a click outside.
  • Touch: long press opens it; the page text selection and the iOS callout are switched off on the area.

Motion

  • Open: pops from the pointer, scale .96 (150ms, ease-out). Close: 160ms fade.
  • Reduced motion: it appears and disappears without movement.