Skip to content

Commit b78a7cd

Browse files
committed
[context menu] Correct generated API metadata
1 parent d60764b commit b78a7cd

17 files changed

Lines changed: 252 additions & 116 deletions

docs/src/app/(docs)/react/components/context-menu/types.md

Lines changed: 61 additions & 62 deletions
Large diffs are not rendered by default.

docs/src/app/(docs)/react/components/menu/types.md

Lines changed: 36 additions & 36 deletions
Large diffs are not rendered by default.

docs/src/app/(docs)/react/components/page.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ A menu that appears at the pointer on right click or long press.
578578
- Separator
579579
- Exports:
580580
- Context Menu - Root
581-
- Props: actionsRef, children, closeParentOnEsc, defaultOpen, disabled, highlightItemOnHover, loopFocus, onOpenChange, onOpenChangeComplete, open, orientation
581+
- Props: actionsRef, children, defaultOpen, disabled, highlightItemOnHover, loopFocus, onOpenChange, onOpenChangeComplete, open, orientation
582582
- Context Menu - Trigger
583583
- Props: className, render, style
584584
- Data Attributes: data-popup-open, data-pressed

packages/react/src/context-menu/index.parts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export { ContextMenuTrigger as Trigger } from './trigger/ContextMenuTrigger';
33

44
export { MenuBackdrop as Backdrop } from '../menu/backdrop/MenuBackdrop';
55
export { MenuPortal as Portal } from '../menu/portal/MenuPortal';
6-
export { MenuPositioner as Positioner } from '../menu/positioner/MenuPositioner';
6+
export { ContextMenuPositioner as Positioner } from './positioner/ContextMenuPositioner';
77
export { MenuPopup as Popup } from '../menu/popup/MenuPopup';
88
export { MenuArrow as Arrow } from '../menu/arrow/MenuArrow';
99
export { MenuGroup as Group } from '../menu/group/MenuGroup';

packages/react/src/context-menu/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export * as ContextMenu from './index.parts';
22

33
export type * from './root/ContextMenuRoot';
44
export type * from './trigger/ContextMenuTrigger';
5+
export type * from './positioner/ContextMenuPositioner';
56

67
export type {
78
MenuBackdropProps as ContextMenuBackdropProps,
@@ -11,10 +12,6 @@ export type {
1112
MenuPortalProps as ContextMenuPortalProps,
1213
MenuPortalState as ContextMenuPortalState,
1314
} from '../menu/portal/MenuPortal';
14-
export type {
15-
MenuPositionerProps as ContextMenuPositionerProps,
16-
MenuPositionerState as ContextMenuPositionerState,
17-
} from '../menu/positioner/MenuPositioner';
1815
export type {
1916
MenuPopupProps as ContextMenuPopupProps,
2017
MenuPopupState as ContextMenuPopupState,
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
'use client';
2+
import type * as React from 'react';
3+
import {
4+
MenuPositioner,
5+
type MenuPositionerProps,
6+
type MenuPositionerState,
7+
} from '../../menu/positioner/MenuPositioner';
8+
import type { BaseUIComponentProps } from '../../internals/types';
9+
10+
export interface ContextMenuPositionerState extends MenuPositionerState {}
11+
12+
/**
13+
* Positions the context menu popup against the pointer or a custom anchor.
14+
* Renders a `<div>` element.
15+
*
16+
* Documentation: [Base UI Context Menu](https://base-ui.com/react/components/context-menu)
17+
*/
18+
export const ContextMenuPositioner: React.ForwardRefExoticComponent<
19+
ContextMenuPositionerProps & React.RefAttributes<HTMLDivElement>
20+
> = MenuPositioner;
21+
22+
export interface ContextMenuPositionerProps
23+
extends
24+
Omit<
25+
MenuPositionerProps,
26+
| keyof BaseUIComponentProps<'div', ContextMenuPositionerState>
27+
| 'anchor'
28+
| 'positionMethod'
29+
| 'sideOffset'
30+
| 'align'
31+
| 'alignOffset'
32+
| 'arrowPadding'
33+
>,
34+
BaseUIComponentProps<'div', ContextMenuPositionerState> {
35+
/**
36+
* An element to position the popup against.
37+
* By default, root context menus are positioned at the pointer, and submenus are positioned
38+
* against their trigger.
39+
*/
40+
anchor?: MenuPositionerProps['anchor'] | undefined;
41+
/**
42+
* Determines which CSS `position` property to use.
43+
* Context menus always use fixed positioning, so passing `'absolute'` has no effect.
44+
* @default 'fixed'
45+
*/
46+
positionMethod?: MenuPositionerProps['positionMethod'] | undefined;
47+
/**
48+
* Distance between the anchor and the popup in pixels.
49+
* Also accepts a function that returns the distance to read the dimensions of the anchor
50+
* and positioner elements, along with its side and alignment.
51+
*
52+
* The function takes a `data` object parameter with the following properties:
53+
* - `data.anchor`: the dimensions of the anchor element with properties `width` and `height`.
54+
* - `data.positioner`: the dimensions of the positioner element with properties `width` and `height`.
55+
* - `data.side`: which side of the anchor element the positioner is aligned against.
56+
* - `data.align`: how the positioner is aligned relative to the specified side.
57+
*
58+
* Defaults to `-5` for root context menus when `side` is not specified and `align` is not
59+
* `'center'`. Otherwise, it defaults to `0`.
60+
*
61+
* @example
62+
* ```jsx
63+
* <ContextMenu.Positioner
64+
* sideOffset={({ side, anchor }) => {
65+
* return side === 'top' || side === 'bottom' ? anchor.height : anchor.width;
66+
* }}
67+
* />
68+
* ```
69+
*/
70+
sideOffset?: MenuPositionerProps['sideOffset'] | undefined;
71+
/**
72+
* How to align the popup relative to the specified side.
73+
* @default 'start'
74+
*/
75+
align?: MenuPositionerProps['align'] | undefined;
76+
/**
77+
* Additional offset along the alignment axis in pixels.
78+
* Also accepts a function that returns the offset to read the dimensions of the anchor
79+
* and positioner elements, along with its side and alignment.
80+
*
81+
* The function takes a `data` object parameter with the following properties:
82+
* - `data.anchor`: the dimensions of the anchor element with properties `width` and `height`.
83+
* - `data.positioner`: the dimensions of the positioner element with properties `width` and `height`.
84+
* - `data.side`: which side of the anchor element the positioner is aligned against.
85+
* - `data.align`: how the positioner is aligned relative to the specified side.
86+
*
87+
* Defaults to `2` for root context menus when `side` is not specified and `align` is not
88+
* `'center'`. Otherwise, it defaults to `0`.
89+
*
90+
* @example
91+
* ```jsx
92+
* <ContextMenu.Positioner
93+
* alignOffset={({ side, anchor }) => {
94+
* return side === 'top' || side === 'bottom' ? anchor.width : anchor.height;
95+
* }}
96+
* />
97+
* ```
98+
*/
99+
alignOffset?: MenuPositionerProps['alignOffset'] | undefined;
100+
/**
101+
* Minimum distance to maintain between the arrow and the edges of the popup.
102+
*
103+
* Root context menus always use `0`. Submenus default to `5`.
104+
*/
105+
arrowPadding?: MenuPositionerProps['arrowPadding'] | undefined;
106+
}
107+
108+
export namespace ContextMenuPositioner {
109+
export type Props = ContextMenuPositionerProps;
110+
export type State = ContextMenuPositionerState;
111+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { MenuPositionerCssVars as ContextMenuPositionerCssVars } from '../../menu/positioner/MenuPositionerCssVars';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { MenuPositionerDataAttributes as ContextMenuPositionerDataAttributes } from '../../menu/positioner/MenuPositionerDataAttributes';

packages/react/src/context-menu/root/ContextMenuRoot.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export interface ContextMenuRootProps extends Omit<
6565
| 'openOnHover'
6666
| 'delay'
6767
| 'closeDelay'
68+
| 'closeParentOnEsc'
6869
| 'onOpenChange'
6970
// Context Menu opens from a pointer position rather than a registered trigger, so the
7071
// render-function form of `children` (which receives the active trigger's payload) is not applicable.
@@ -76,6 +77,14 @@ export interface ContextMenuRootProps extends Omit<
7677
onOpenChange?:
7778
| ((open: boolean, eventDetails: ContextMenuRoot.ChangeEventDetails) => void)
7879
| undefined;
80+
/**
81+
* @ignore
82+
* @deprecated This prop has no effect on Context Menu.
83+
*/
84+
closeParentOnEsc?: Menu.Root.Props['closeParentOnEsc'] | undefined;
85+
/**
86+
* The content of the context menu.
87+
*/
7988
children?: React.ReactNode | undefined;
8089
}
8190

packages/react/src/context-menu/trigger/ContextMenuTriggerDataAttributes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export enum ContextMenuTriggerDataAttributes {
66
*/
77
popupOpen = CommonTriggerDataAttributes.popupOpen,
88
/**
9-
* Present when the trigger is pressed.
9+
* Present when the corresponding context menu is open.
1010
*/
1111
pressed = CommonTriggerDataAttributes.pressed,
1212
}

0 commit comments

Comments
 (0)