Make your AI a shadcn expert

Shadcn Context Menu

React context menu for right-click actions on a row or file. Built with TypeScript and Tailwind CSS for Next.js using Base UI — submenus, shortcuts, and checkboxes.

The shadcn context menu is a list of actions at the pointer. Right-click — or long-press — the trigger and the menu opens there. Use it for a file, a table row, or a canvas object. A button that should open a menu is a Dropdown Menu.

Scroll to load preview...

Looking for a neobrutalism version for shadcn?

Same context menu, thicker borders. The NeoBrutalism context menu is the kit if you want that look.

Usage

import {
  ContextMenu,
  ContextMenuContent,
  ContextMenuItem,
  ContextMenuTrigger,
} from "@/components/ui/context-menu"
<ContextMenu>
  <ContextMenuTrigger>Right click here</ContextMenuTrigger>
  <ContextMenuContent>
    <ContextMenuItem>Profile</ContextMenuItem>
    <ContextMenuItem>Billing</ContextMenuItem>
    <ContextMenuItem>Team</ContextMenuItem>
    <ContextMenuItem>Subscription</ContextMenuItem>
  </ContextMenuContent>
</ContextMenu>

The trigger is the right-click target. onSelect on an item fires when they pick it, then the menu closes.

Composition

ContextMenuTrigger
ContextMenuLabel
ContextMenuItem
ContextMenuItem
ContextMenuSeparator
ContextMenuSeparator

Basic

Back, Forward, Reload. Forward stays in the list, disabled.

Scroll to load preview...

ContextMenuSub nests More Tools. Keep it one level.

Scroll to load preview...

Shortcuts

ContextMenuShortcut paints ⌘S. It does not bind the key.

Scroll to load preview...

Groups

ContextMenuGroup plus a separator. File, Edit, then the red row.

Scroll to load preview...

Icons

Icons sit in the item before the label.

Scroll to load preview...

Checkboxes

ContextMenuCheckboxItem for toggles that stack independently.

Scroll to load preview...

Radio

ContextMenuRadioGroup plus ContextMenuRadioItem when only one value can be on.

Scroll to load preview...

Destructive

variant="destructive" on the last item. Put it at the bottom.

Scroll to load preview...

Sides

align / collision on the content. Right-click near an edge and the menu stays on screen.

Scroll to load preview...

RTL

Wrap with DirectionProvider and dir="rtl". Submenus open toward the start.

Scroll to load preview...

API

Prop

Type

ContextMenuItem

Prop

Type

ContextMenuCheckboxItem takes checked and onCheckedChange. ContextMenuRadioGroup takes value and onValueChange. ContextMenuLabel and ContextMenuSubTrigger take inset.

Keyboard

KeyAction
Space / EnterActivate the focused item
ArrowDown / ArrowUpNext / previous item
ArrowRight / ArrowLeftOpen or close a submenu
EscapeClose the menu and return to the trigger
A-ZTypeahead to an item

Long-press the trigger on a touch device.

Notes

Shortcuts are labels

ContextMenuShortcut does not bind a key. Show ⌘S in the row, then listen for the combination yourself.

Right-click on the trigger replaces the browser menu. Don’t wrap a link if they still need Open in new tab.

With other components

Questions

Was this page helpful?

Sign in to leave feedback.