Back to components
ElementOverlayFree

Context Menu React component

A right-click context menu with checkbox and radio items, nested submenus, viewport edge clamping and full keyboard navigation.

About the Context Menu component

Context Menu replaces the browser's right-click menu on any area you wrap with it. The menu opens at the pointer, moves back inside the window if it would overflow the right or bottom edge, and closes on a click elsewhere, on scroll and on resize.

Each entry in items has a kind: item, checkbox, radio, separator, label or submenu, with optional shortcut text and disabled and danger flags. Submenus open on hover or with the right arrow key and can be nested. The arrow keys, Home and End move through the items and skip separators, labels and disabled entries, Enter or Space picks one and Escape closes the menu. Rows use the menuitem, menuitemcheckbox and menuitemradio roles with aria-checked.

When to use it

Use it where people expect a right-click: file and folder lists, table rows, items on a canvas or a board, chat messages and editors.

For a menu that opens from a visible button, use Dropdown Menu. For an app-style File, Edit and View bar, use Menubar.

Installation

Add the Context Menu component to your project with the shadcn CLI. It lands in components/context-menu.tsx as plain React + Tailwind CSS source you own and can edit.

Install
Copied!
npx shadcn@latest add @reactframe/context-menu

Or copy the source by hand and install its dependencies:

Install
Copied!
npm install motion clsx tailwind-merge

Related components

Hover Card
Free
Confirm Dialog
Free
Command Palette
Free
Avatar
Free
Avatar Group
Free
Divider
Free