You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/components/actions/use-context-menu.docs.mdx
+28-15Lines changed: 28 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ import { Meta } from '@storybook/blocks';
6
6
7
7
## Purpose
8
8
9
-
`useContextMenu` is a React hook that enables components to display context menus (like `Menu` or `CommandMenu`) at the exact cursor position where the user right-clicked or triggered a context action. Unlike [`useAnchoredMenu`](./use-anchored-menu.docs.mdx) which anchors menus to specific elements, `useContextMenu` positions menus at cursor coordinates, making it perfect for traditional right-click context menus.
9
+
`useContextMenu` is a React hook that enables components to display context menus (like `Menu` or `CommandMenu`) at the exact cursor position where the user right-clicked or triggered a context action. Unlike [`useAnchoredMenu`](./use-anchored-menu.docs.mdx) which anchors menus to specific elements, `useContextMenu` positions menus at cursor coordinates or centers them on the target element, making it perfect for traditional right-click context menus and programmatic menu opening.
10
10
11
11
The hook automatically handles `onContextMenu` event binding and provides a clean API for both automatic (right-click) and programmatic menu opening.
12
12
@@ -32,17 +32,17 @@ function useContextMenu<P, T = ComponentProps<typeof MenuTrigger>>(
32
32
targetRef:RefObject<HTMLElement>;
33
33
34
34
/**
35
-
* Programmatically opens the menu at the specified event coordinates.
35
+
* Programmatically opens the menu at the specified coordinates or element center.
36
36
* Runtime props are merged with defaultMenuProps (runtime props take precedence).
37
37
*
38
-
* @paramevent - The pointer/mouse event containing coordinates for positioning
39
38
* @paramprops - Props to pass to the menu component (optional, defaults to defaultMenuProps)
40
39
* @paramtriggerProps - Additional props for MenuTrigger (merged with defaultTriggerProps)
40
+
* @paramevent - The pointer/mouse event containing coordinates for positioning (optional, centers on element if not provided)
0 commit comments