Skip to content

Context Menu

A menu that appears at the pointer on right click or long press.

API Reference

Installation

pnpm dlx shadcn@latest add @frontal-labs/context-menu

Usage

import {
  ContextMenu,
  ContextMenuCheckboxItem,
  ContextMenuContent,
  ContextMenuGroup,
  ContextMenuItem,
  ContextMenuLabel,
  ContextMenuRadioGroup,
  ContextMenuRadioItem,
  ContextMenuSeparator,
  ContextMenuSub,
  ContextMenuSubContent,
  ContextMenuSubTrigger,
  ContextMenuTrigger,
} from "@/components/ui/context-menu";
<ContextMenu>
  <ContextMenuTrigger className="flex h-32 items-center justify-center rounded-md border border-dashed">
    Right click here
  </ContextMenuTrigger>
  <ContextMenuContent>
    <ContextMenuItem>Back</ContextMenuItem>
    <ContextMenuItem>Forward</ContextMenuItem>
    <ContextMenuSeparator />
    <ContextMenuItem render={<Link href="/docs" />}>Documentation</ContextMenuItem>
    <ContextMenuSeparator />
    <ContextMenuSub>
      <ContextMenuSubTrigger>More tools</ContextMenuSubTrigger>
      <ContextMenuSubContent>
        <ContextMenuItem>Inspect</ContextMenuItem>
        <ContextMenuItem>View source</ContextMenuItem>
      </ContextMenuSubContent>
    </ContextMenuSub>
  </ContextMenuContent>
</ContextMenu>

API Reference

ContextMenu

Root component. Alias for ContextMenu.Root from Base UI.

ContextMenuTrigger

An area that opens the menu on right click or long press. Renders a <div> element.

ContextMenuContent

Popup container that displays the menu content at the pointer. The surface is elevated with shadow-menu and surface-ring.

About dark: the menu renders with the dark palette by default. Pass dark={false} when it should follow the ambient theme instead — next-themes sets dark on <html> and the portal lands in document.body, inside it, so the menu can pick up the ambient theme once dark is turned off. For a menu opened from a .dark region scoped mid-page, which a portal does escape, rendering into the scoped node is usually the better tool. dark applies .dark to the positioner inside the portal, so the tokens inherit down to the popup and everything within it.

ContextMenuGroup

Groups related menu items. Alias for ContextMenu.Group from Base UI.

ContextMenuItem

Individual menu item.

Using inset: When mixing items with and without icons, use inset on icon-less items to maintain alignment:

<ContextMenuItem><PencilIcon /> Edit</ContextMenuItem>
<ContextMenuItem inset>Properties</ContextMenuItem>

Linking: to make an item navigate, pass a link through render:

<ContextMenuItem render={<Link href="/docs" />}>Docs</ContextMenuItem>

ContextMenuCheckboxItem

Checkbox menu item with a check indicator.

ContextMenuRadioGroup

Groups radio menu items. Alias for ContextMenu.RadioGroup from Base UI.

ContextMenuRadioItem

Radio menu item. Styled wrapper for ContextMenu.RadioItem from Base UI.

ContextMenuLabel

Label for a menu group. Styled wrapper for ContextMenu.GroupLabel from Base UI.

ContextMenuSeparator

Visual separator between menu items.

ContextMenuShortcut

Displays keyboard shortcut text. Custom component (not a Base UI wrapper).

ContextMenuSub

Submenu container. Alias for ContextMenu.SubmenuRoot from Base UI.

ContextMenuSubTrigger

Trigger for opening a submenu.

ContextMenuSubContent

Popup for submenu content. Renders through ContextMenuContent, so it takes the same props — including dark — and carries the same shadow-menu + surface-ring elevation.

ContextMenuPortal

Renders the popup into a portal. Alias for ContextMenu.Portal from Base UI.

Examples

Nested Menu

With Checkbox

With Group Label

With Icons

With Radio Group

With Checkbox Group

Wrap several ContextMenuCheckboxItem elements in a ContextMenuGroup to keep related toggles together.