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.
Right-clicking outside closes the menu and allows the native browser menu to appear.
RTL Support
Set the direction once with DirectionProvider (or <html dir="rtl">) and the context menu follows. It opens to the left of the pointer, sub-menus open to the left, and the arrow keys that open and close sub-menus swap.
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 the top corner at the cursor (top-left, or top-right in RTL). 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 -> <html dir>).
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.