Search

Find a component, token or page

Base · Overlays

Context menu

A menu of actions that opens at the pointer when an area is right-clicked.

HTML / JSPlannedReactStableReact NativeDraftSwift (SwiftUI)PlannedGodotPlannedVueDraftSvelteDraftSolidDraft
Reviewed
Right-click shipment SH-20418

Props

tsx
import {
  ContextMenu,
  ContextMenuContent,
  ContextMenuGroup,
  ContextMenuItem,
  ContextMenuLabel,
  ContextMenuSeparator,
  ContextMenuShortcut,
  ContextMenuTrigger,
} from "@/components/ui/context-menu"

<ContextMenu>
  <ContextMenuTrigger className="rounded-lg border border-dashed p-8 text-sm">
    Right-click shipment SH-20418
  </ContextMenuTrigger>
  <ContextMenuContent>
    <ContextMenuGroup>
      <ContextMenuLabel>Shipment</ContextMenuLabel>
      <ContextMenuItem>
        Open <ContextMenuShortcut>⌘O</ContextMenuShortcut>
      </ContextMenuItem>
      <ContextMenuItem>Copy tracking link</ContextMenuItem>
      <ContextMenuItem>Assign driver</ContextMenuItem>
    </ContextMenuGroup>
    <ContextMenuSeparator />
    <ContextMenuItem variant="destructive">Cancel shipment</ContextMenuItem>
  </ContextMenuContent>
</ContextMenu>

Overview

A context menu offers the actions for the thing under the pointer: a table row, a file, a map pin. It is a shortcut for people who look for it, so every action in it must also be reachable another way.

When to use

  • On rows, cards and canvas objects in tools people use all day, to speed up frequent actions.
  • When the same actions already exist in a visible Dropdown menu or toolbar.

When not to use

  • As the only way to reach an action. Nothing on screen says a context menu exists; add a Dropdown menu.
  • On text, links and form fields, where people expect the browser's own menu.
  • For application-wide commands: use a Menubar or a Command palette.

Anatomy

  1. Trigger

    The area that responds to right-click. It wraps your content and adds no styling.

  2. Content

    The floating list, placed at the pointer.

  3. Group and label

    Related items with an optional heading. A label must sit inside a group.

  4. Item

    An action, with an optional icon and shortcut. Has a destructive variant.

  5. Checkbox, radio and submenu items

    Same as in a Dropdown menu.

Props

The contract every language implements. Names follow each language’s conventions (camelCase in React, snake_case in Rust).

PropTypeDefaultDescription
side"right" | "left" | "top" | "bottom"rightThe side of the pointer the menu opens on. Set on ContextMenuContent.
align"start" | "center" | "end"startHow the menu lines up with the pointer along that side.
labelstringRight-click shipment SH-20418Text shown in the trigger area in this example.
onOpenChangefunction–Called when the menu opens or closes. Set on the root.

States

Closed
The trigger area looks like normal content.
Open
The menu appears at the pointer position and takes focus.
Item highlighted
The item under the pointer or keyboard focus has a muted background.

Accessibility

Role: menu

KeysAction
Shift+F10/Menu keyWith focus inside the trigger area, opens the menu.
Arrow Down/Arrow UpMoves the highlight between items.
Home/EndHighlights the first or last item.
Enter/SpaceActivates the highlighted item and closes the menu.
Arrow Right/Arrow LeftOpens a submenu, or closes it and returns to its parent.
A–ZHighlights the next item that starts with the typed characters.
EscapeCloses the menu.
  • The keyboard shortcut only works if something inside the trigger area can receive focus.
  • On touch screens the menu opens on long-press.
  • Provide every action elsewhere in the interface as well.

Design tokens

Change any of these in Foundations and this component follows, in every language.

Platform notes

HTML / JS
Planned
Not built in HTML / JS yet.
React
Stable
Matches the contract with no platform differences.
React Native
Draft
Prop-driven: pass `items`, with the trigger area as children. Opens on long-press (and right-click on web) at the touch point on wide windows, or as an action sheet on phones.
Swift (SwiftUI)
Planned
Not built in Swift yet.
Godot
Planned
Not built in Godot yet.
Vue
Draft
Usage snippet only; same props and behavior as the React component.
Svelte
Draft
Usage snippet only; same props and behavior as the React component.
Solid
Draft
Usage snippet only; same props and behavior as the React component.

Related