Shadcn.io is not affiliated with official shadcn/ui
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.
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:
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-menuWhy 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:
Actions with visual icons
Icons help users quickly identify common actions:
Toggle settings and preferences
Perfect for view options and application settings:
Choose between options
Radio groups let users pick one choice from several:
Organize complex actions
Submenus keep related actions grouped without clutter:
Handle restricted content
Show what's available and what isn't with disabled states:
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
| Component | Purpose | Key Props |
|---|---|---|
ContextMenu | Root container | dir, onOpenChange, modal |
ContextMenuTrigger | Right-click target | asChild, disabled |
ContextMenuContent | Menu container | loop, alignOffset, avoidCollisions |
ContextMenuItem | Individual action | disabled, onSelect |
Interactive Elements
| Component | Purpose | Key Props |
|---|---|---|
ContextMenuCheckboxItem | Toggle option | checked, onCheckedChange, disabled |
ContextMenuRadioGroup | Single choice group | value, onValueChange |
ContextMenuRadioItem | Radio option | value, disabled |
ContextMenuSub | Nested submenu | defaultOpen, open, onOpenChange |
Keyboard Navigation
| Key | Action |
|---|---|
Space | Activates the focused item |
Enter | Activates the focused item |
ArrowDown | Moves focus to the next item |
ArrowUp | Moves focus to the previous item |
ArrowRight | Opens submenu when focused on trigger |
ArrowLeft | Closes submenu when focused on trigger |
Escape | Closes 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
Was this page helpful?
Sign in to leave feedback.
Shadcn Command
React command palette component with fast search and keyboard shortcuts. Built with TypeScript and Tailwind CSS for Next.js applications using cmdk library.
Shadcn Data Table
React data table component with sorting, filtering, pagination, and row selection. Built with TypeScript and Tailwind CSS for Next.js using TanStack Table.