Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Context Menu examples · Standard

Simple Context Menu for React

A right-click area that opens Back, Forward, Reload and More Options.

Framework
UI library

The smallest context menu: right-click the area and four plain items appear, Back, Forward, Reload and More Options. Start here and add icons, shortcuts and groups as the menu grows.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

What opens the menu?

A right-click inside the dashed area, which reads Right click here on a mouse and Long press here on a touch screen. The area is ContextMenuTrigger; a long press on it opens the menu too. Wrap your own row, file or canvas in the trigger instead.

Which parts make up the menu?

ContextMenu, the trigger, the popup and four ContextMenuItems in one ContextMenuGroup. Nothing else is needed for a flat list.

How do I run an action when an item is chosen?

Pass onClick to each ContextMenuItem.

The menu closes after the action runs.

Does it replace the browser's menu?

Inside the trigger, yes: a right-click there opens this menu instead of the browser's. Keep the trigger to the area that needs custom actions.

How do keyboard and touch users find these actions?

The arrow keys move through an open menu, Enter runs an item and Escape closes it. A right-click is easy to miss, so also offer the same actions from a visible button, such as a Dropdown Menu.

How wide is the menu?

w-56 on the popup. Set your own width class for longer labels.