Join our Discord Community

Shadcn Context Menu

React context menu component for right-click actions and submenus. Built with TypeScript and Tailwind CSS for Next.js applications using Radix UI primitives.

Context menu positioning?

Join our Discord community for help from other developers.


Ever built an app where users kept asking "How do I right-click on this?" or watched them hunt through toolbars for actions they expected to find in a context menu? Yeah, missing right-click support makes web apps feel broken to desktop users. This shadcn/ui context menu brings native OS-style interactions to your React application.

Context menu showcase

Right-click interactions that feel familiar:

Loading component...

Built on Radix UI primitives with full accessibility support. Styled with Tailwind CSS so it matches your design system instead of looking like a generic dropdown menu.

npx shadcn@latest add context-menu

Why context menus actually improve user experience

Here's the thing—context menus aren't just about adding features, they're about meeting user expectations. Desktop users have been right-clicking for decades. When your web app doesn't respond to right-clicks, it feels incomplete.

Think about how you use your computer. Right-click a file, get file operations. Right-click text, get editing options. Right-click in VS Code, get code actions. Users bring these muscle memories to your app. This free shadcn context menu component lets you honor those expectations in your React projects.

Context menus also solve the toolbar clutter problem. Instead of cramming every possible action into your interface, you put common actions where users can see them and secondary actions behind a right-click. Your Next.js application stays clean while power users get the tools they need in TypeScript-safe, accessible components. React developers love this pattern because it keeps interfaces minimal while maintaining functionality.

Common context menu patterns you'll actually use

File and folder operations

The classic right-click menu for managing items:

Loading component...

Actions with visual icons

Icons help users quickly identify common actions:

Loading component...

Toggle settings and preferences

Perfect for view options and application settings:

Loading component...

Choose between options

Radio groups let users pick one choice from several:

Loading component...

Organize complex actions

Submenus keep related actions grouped without clutter:

Loading component...

Handle restricted content

Show what's available and what isn't with disabled states:

Loading component...

Features

This free open source context menu component includes everything you need:

  • TypeScript-first - Full type safety with proper event handlers and menu state
  • Radix UI powered - Battle-tested accessibility and keyboard navigation
  • Cursor positioning - Appears exactly where users right-click, like native apps
  • Tailwind CSS styled - Customize with utilities, not fighting component CSS
  • Mobile optimized - Long-press works on touch devices automatically
  • Submenu support - Nest actions without creating navigation nightmares
  • Keyboard accessible - Arrow keys, Enter, Escape work exactly as expected
  • Portal rendering - Avoids z-index conflicts by rendering in document body

API Reference

Core Components

ComponentPurposeKey Props
ContextMenuRoot containerdir, onOpenChange, modal
ContextMenuTriggerRight-click targetasChild, disabled
ContextMenuContentMenu containerloop, alignOffset, avoidCollisions
ContextMenuItemIndividual actiondisabled, onSelect

Interactive Elements

ComponentPurposeKey Props
ContextMenuCheckboxItemToggle optionchecked, onCheckedChange, disabled
ContextMenuRadioGroupSingle choice groupvalue, onValueChange
ContextMenuRadioItemRadio optionvalue, disabled
ContextMenuSubNested submenudefaultOpen, open, onOpenChange

Keyboard Navigation

KeyAction
SpaceActivates the focused item
EnterActivates the focused item
ArrowDownMoves focus to the next item
ArrowUpMoves focus to the previous item
ArrowRightOpens submenu when focused on trigger
ArrowLeftCloses submenu when focused on trigger
EscapeCloses the context menu

Production tips

Make right-click discoverable. This free shadcn/ui context menu works perfectly, but users need to know right-clicking does something. Add subtle hints like "Right-click for options" or show a small menu icon next to items. Your React component handles the functionality—you handle the discoverability that makes it useful in Next.js applications.

Group actions logically. Don't dump 15 random actions in one menu. Group by action type—File operations, Edit actions, View options. Use separators between groups. This TypeScript component provides the structure—you provide the organization that actually helps users. React applications benefit from logical grouping because it matches how users think about tasks.

Put dangerous actions last. Delete, Remove, and other destructive actions should be at the bottom of menus, preferably with visual warnings. Users scan menus top to bottom. Your JavaScript context menu should protect against accidental clicks, not encourage them.

Test with real content. Those neat demos with "Copy" and "Paste" work great until you have "Export Selected Items to PDF with Custom Template Settings". Long action names break layouts. This open source shadcn component handles the UI—you handle the content that actually reflects production usage.

Mobile needs special consideration. Long-press to open context menus works, but touch targets need to be finger-friendly. Consider showing context actions in different ways on small screens—maybe as bottom sheets or action buttons instead of tiny dropdown menus.

Integration with other components

Context menus naturally extend your existing shadcn components in React applications. Use Button components within menu items for complex actions that need additional styling or loading states.

For rich menu displays, combine with Avatar components to show user actions or Badge components for showing status indicators next to menu options. This open source pattern works well for team collaboration interfaces.

When building content management systems, pair context menus with Dialog components for confirmation actions. Your JavaScript context menu triggers the confirmation—the dialog handles the actual destructive operation safely.

For form-heavy applications, context menus can trigger Sheet workflows for editing content. Separator components help organize complex menu structures into logical action groups that make sense to users.

Questions you might have