Displays a context menu of actions triggered by right-click on a target.
Philosophy
Context menus are power-user shortcuts that surface relevant actions where the user already is. This implementation is built directly on the @gentleduck/primitives/context-menu primitives, so right-click behavior, keyboard interactions, and submenu semantics stay consistent.
How It's Built
Installation
npx @gentleduck/cli add context-menu
npx @gentleduck/cli add context-menu
Usage
import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger,} from "@/components/ui/context-menu"
import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger,} from "@/components/ui/context-menu"
Right-clicking outside closes the menu and allows the native browser menu to appear.
RTL Support
Set dir="rtl" on ContextMenu for a local override, or set DirectionProvider once at app/root level for global direction.
Motion
Alpha: Motion Compositions
Motion components work standalone, but some compositions may behave unexpectedly — this is still under active development. If you find a broken composition, please file an issue.
Use MotionContextMenu and MotionContextMenuContent for smooth enter/exit animations powered by motion. The transform origin is fixed to top-left since the menu appears at the cursor position. For animated sub-menus, use MotionContextMenuSub and MotionContextMenuSubContent.
Requires the motion package. Use MotionContextMenu instead of ContextMenu and MotionContextMenuContent instead of ContextMenuContent. For sub-menus, use MotionContextMenuSub and MotionContextMenuSubContent. All other sub-components stay the same.
API Reference
Components in this file wrap @gentleduck/primitives/context-menu.
ContextMenu
Prop
Type
Default
Description
children
React.ReactNode
-
Context menu content (trigger + menu content)
modal
boolean
true
Whether interaction outside the menu is blocked while open
dir
'ltr' | 'rtl'
-
Text direction. Resolved by primitives useDirection (dir prop -> DirectionProvider -> 'ltr').
Additional props inherited from ContextMenuPrimitive.SubContent
MotionContextMenu
Same props as ContextMenu. Wraps with useMotionRoot for exit animation support. Requires the motion package.
MotionContextMenuContent
Same props as ContextMenuContent. Adds scale, blur, and opacity enter/exit animation with springBouncy transition. Transform origin fixed to top-left. Requires the motion package.
MotionContextMenuSub
Same props as ContextMenuSub. Wraps sub-menu with useMotionRoot for exit animation support. Requires the motion package.
MotionContextMenuSubContent
Same props as ContextMenuSubContent. Adds scale and blur enter/exit animation in a Portal. Requires the motion package.