Theme studio

Design a theme, preview it live, then export it. Saved in this browser.

Quick picks #10b981
Generated scale
50100200300400500600700800900
Some text is below AA

ContextMenu

  • Stable
  • WCAG 2.2 evidence
  • RTL
  • Web · iOS · Android

The menu of actions for an element, opened where the user asks for it: right-click, long-press on touch screens, and from the keyboard with Shift+F10 or the ContextMenu key (the browser reports both as a contextmenu event on the focused element; on macOS, Control+Enter). Built on React Aria MenuTrigger (trigger="contextMenu") + Popover + Menu, so the menu keyboard model applies: arrows, Home/End, type-ahead, Enter; Escape closes it and returns focus to the element (WCAG 2.1.1, 2.4.3, 4.1.2). Right-clicking outside closes it. A context menu is hard to discover: never make it the only way to reach an action; also offer visible row actions or a Menu button.

import { ContextMenu } from "@nexera-ui/react";
Loading example…
4
examples
31
props
2
live controls
3
platforms
4
WCAG criteria
1
block uses it

Try every prop. Copy the code.

Change the props and the code updates. Check light and dark, LTR and RTL, and phone width.

Loading…
defaultOpen
platform
Generated code
import { ContextMenu } from "@nexera-ui/react";

<ContextMenu />

Examples 3

The same examples as Storybook, rendered live. Open Code to copy one.

With header

Figma Type=With header: the header ("3 people selected") also names the menu.

Loading example…

With quick actions

Figma Type=With quick actions: a named group of tiles above the items; the arrow keys reach every tile.

Loading example…

Platforms

platform="ios" and "android" open the Figma System menu surface.

Loading example…

Props 31

Press "Try it" on a card to load that prop into the playground.

31 props shown

trigger*Nexera
ReactElement<DOMAttributes<FocusableElement>, string>

The element the menu belongs to: right-click, long-press (touch), Shift+F10 or the ContextMenu key on it opens the menu at that point. It must be a DOM element that can take keyboard focus (tabIndex={0}) and has an interactive role, for example a row or a card with role="button", so keyboard users can open the menu too (WCAG 2.1.1).

Default –
isOpenNexera
boolean

Whether the menu is open (controlled). Use with onOpenChange.

Default –
defaultOpenNexera
boolean

Whether the menu is open on first render (uncontrolled). It then opens at the trigger.

Default false
onOpenChangeNexera
(isOpen: boolean) => void

Called when the menu opens or closes.

Default –
platformNexera
"web" | "ios" | "android"

Platform look. iOS and Android use the Figma System menu surface and rows. Defaults to the NexeraProvider.

Default "web"
classNameNexera
string

Extra classes for the menu surface, merged last so they win over the defaults.

Default –
styleNexera
CSSProperties

Inline style for the menu surface.

Default –
typeNexera
"default" | "with-header" | "with-quick-actions"

Layout: default lists the items; with-header adds a heading such as "3 people selected"; with-quick-actions adds a row of icon tiles above the items.

Default "default"
headerNexera
ReactNode

Heading above the items, for example "3 people selected". It also names the menu.

Default –
quickActionsNexera
readonly ContextMenuQuickAction[]

Tiles above the items: up to four frequent actions such as Copy, Share, Star and Delete.

Default –
quickActionsLabelNexera
string

Accessible name of the quick-actions group. Translate it for your locale.

Default "Quick actions"
childrenReact Aria
ReactNode | ((item: T) => ReactNode)

The contents of the collection.

Default –
escapeKeyBehaviorReact Aria
"clearSelection" | "none"

Whether pressing the escape key should clear selection in the menu or not. Most experiences should not modify this option as it eliminates a keyboard user's ability to easily clear selection. Only use if the escape key is being handled externally or should not trigger selection clearing contextually.

Default 'clearSelection'
autoFocusReact Aria
boolean | FocusStrategy

Where the focus should be set.

Default –
shouldFocusWrapReact Aria
boolean

Whether keyboard navigation is circular.

Default –
onActionReact Aria
(key: Key, value: T) => void

Handler that is called when an item is selected.

Default –
onCloseReact Aria
() => void

Handler that is called when the menu should close after selecting an item.

Default –
itemsReact Aria
Iterable<T>

Item objects in the collection.

Default –
disabledKeysReact Aria
Iterable<Key>

The item keys that are disabled. These items cannot be selected, focused, or otherwise interacted with.

Default –
selectionModeReact Aria
"none" | "single" | "multiple"

The type of selection that is allowed in the collection.

Default –
disallowEmptySelectionReact Aria
boolean

Whether the collection allows empty selection.

Default –
selectedKeysReact Aria
Iterable<Key> | "all"

The currently selected keys in the collection (controlled).

Default –
defaultSelectedKeysReact Aria
Iterable<Key> | "all"

The initial selected keys in the collection (uncontrolled).

Default –
onSelectionChangeReact Aria
(keys: Selection) => void

Handler that is called when the selection changes.

Default –
idReact Aria
string

The element's unique identifier. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id).

Default –
aria-labelReact Aria
string

Defines a string value that labels the current element.

Default –
aria-labelledbyReact Aria
string

Identifies the element (or elements) that labels the current element.

Default –
aria-describedbyReact Aria
string

Identifies the element (or elements) that describes the object.

Default –
renderEmptyStateReact Aria
() => ReactNode

Provides content to display when there are no items in the menu.

Default –
shouldCloseOnSelectReact Aria
boolean

Whether the menu should close when the menu item is selected.

Default –
dependenciesReact Aria
readonly any[]

Values that should invalidate the item cache when using dynamic collections.

Default –

* Required. React Aria props shown are the ones most apps use; the component accepts the rest of its React Aria props too.

Accessible by default.

Built on React Aria, and covered by the WCAG 2.2 evidence generated on every build.

WCAG 2.2 evidence

4 direct · 0 supporting
  • 1.3.1Info and RelationshipsLevel A · tested directly
  • 2.1.1KeyboardLevel A · tested directly
  • 2.4.3Focus OrderLevel A · tested directly
  • 4.1.2Name, Role, ValueLevel A · tested directly

Fits any width.

Nexera components respond to the space they are given. Drag the corner of the frame, or pick a width.

0 px · drag the corner

Styling hooks

Pass className to add Tailwind classes (merged last). State is exposed as data attributes, so you can style it with variants like data-pressed:.

  • data-disabled
  • data-hovered
  • data-pressed
Usage
<ContextMenu className="data-disabled:opacity-90 shadow-sm" />

Used in blocks

Related components