@xsolla/xui-context-menu 0.202.2 → 0.202.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -44,19 +44,7 @@ interface ContextMenuOptionItemProps extends ContextMenuItemBaseProps {
44
44
  leadingIcon?: ReactNode;
45
45
  /** Status indicator slot rendered before the label group (e.g. `<Status />`). */
46
46
  status?: ReactNode;
47
- /**
48
- * Vertical placement of the `status` slot within the cell.
49
- *
50
- * - `true` (default) — the indicator is aligned to the **first line** of the
51
- * label and stays there when the label wraps or a `description` makes the
52
- * cell taller.
53
- * - `false` — the indicator is centred on the full height of the cell. This
54
- * restores the previous behaviour for consumers that depend on it.
55
- *
56
- * Has no effect when `status` is not provided.
57
- *
58
- * @default true
59
- */
47
+ /** Align `status` to the label's first line rather than the cell's full height. Defaults to `true`. */
60
48
  statusTopAlignment?: boolean;
61
49
  iconWrapper?: ReactNode;
62
50
  slot?: ReactNode;
@@ -73,20 +61,14 @@ interface ContextMenuOptionItemProps extends ContextMenuItemBaseProps {
73
61
  onSelect?: () => void;
74
62
  onCheckedChange?: (checked: boolean) => void;
75
63
  }
76
- /**
77
- * A search cell rendered at the top of the menu. When `searchable` is set on the
78
- * panel this cell is auto-rendered and stays mounted even when the query matches
79
- * nothing, so the user can clear it without reopening the menu. A trailing clear
80
- * (×) button appears whenever the field has a value; pressing it empties the
81
- * query (fires `onValueChange("")`) and refocuses the input.
82
- */
64
+ /** A search cell at the top of the menu; auto-rendered when `searchable` is set. */
83
65
  interface ContextMenuSearchItemProps extends ContextMenuItemBaseProps {
84
66
  type: "search";
85
67
  /** Controlled value of the search input. */
86
68
  value?: string;
87
69
  /** Raw change event; fires alongside `onValueChange`. */
88
70
  onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
89
- /** Change callback with the next string value. Also invoked with `""` when the clear button is pressed. */
71
+ /** Next string value. Also fires with `""` when the clear button is pressed. */
90
72
  onValueChange?: (value: string) => void;
91
73
  placeholder?: string;
92
74
  autoFocus?: boolean;
@@ -112,25 +94,11 @@ interface ContextMenuProps extends ThemeOverrideProps {
112
94
  emptyMessage?: string;
113
95
  empty?: ReactNode;
114
96
  trigger?: ReactNode;
115
- /**
116
- * When `true`, the trigger fills the full width of its parent instead of
117
- * shrinking to its content width. Defaults to `false`.
118
- */
97
+ /** Trigger fills its parent's width instead of hugging its content. Defaults to `false`. */
119
98
  triggerFullWidth?: boolean;
120
- /**
121
- * Menu placement relative to the trigger element. The `*-center` variants
122
- * horizontally center the panel on the trigger; every variant auto-flips on
123
- * the vertical axis (and `start`/`end` flip horizontally) when the menu
124
- * would clip the viewport. Only applies to trigger-anchored menus (ignored
125
- * when `position` is set). Defaults to `"bottom-start"`.
126
- */
99
+ /** Placement relative to the trigger; auto-flips to stay in the viewport. Ignored when `position` is set. Defaults to `"bottom-start"`. */
127
100
  placement?: ContextMenuPlacement;
128
- /**
129
- * Gap in pixels between the trigger and the menu. When `withArrow` is set
130
- * this is measured to the arrow's tip; otherwise to the panel edge. Only
131
- * applies to trigger-anchored menus (ignored when `position` is set).
132
- * Defaults to `4`.
133
- */
101
+ /** Gap in px to the panel edge, or to the arrow tip when `withArrow` is set. Defaults to `4`. */
134
102
  offset?: number;
135
103
  position?: ContextMenuPosition;
136
104
  isOpen?: boolean;
@@ -138,11 +106,7 @@ interface ContextMenuProps extends ThemeOverrideProps {
138
106
  closeOnSelect?: boolean;
139
107
  width?: number | string;
140
108
  maxHeight?: number;
141
- /**
142
- * Render a directional arrow on the panel edge pointing toward the trigger,
143
- * mirroring the Tooltip arrow. Only applies to trigger-anchored menus.
144
- * Defaults to `false`.
145
- */
109
+ /** Arrow on the panel edge pointing at the trigger. Defaults to `false`. */
146
110
  withArrow?: boolean;
147
111
  onSelect?: (item: ContextMenuOptionItemProps) => void;
148
112
  "aria-label"?: string;
@@ -151,15 +115,12 @@ interface ContextMenuProps extends ThemeOverrideProps {
151
115
  style?: CSSProperties;
152
116
  }
153
117
  interface ContextMenuSubmenuProps {
154
- /** Text label for the submenu trigger item */
155
118
  label: ReactNode;
156
- /** Leading icon for the trigger item */
157
119
  icon?: ReactNode;
158
- /** Whether the trigger item is disabled */
159
120
  disabled?: boolean;
160
121
  /** Submenu panel contents */
161
122
  children: ReactNode;
162
- /** Size inherited from parent */
123
+ /** Inherited from the parent menu when omitted */
163
124
  size?: ContextMenuSize;
164
125
  "data-testid"?: string;
165
126
  }
package/native/index.d.ts CHANGED
@@ -44,19 +44,7 @@ interface ContextMenuOptionItemProps extends ContextMenuItemBaseProps {
44
44
  leadingIcon?: ReactNode;
45
45
  /** Status indicator slot rendered before the label group (e.g. `<Status />`). */
46
46
  status?: ReactNode;
47
- /**
48
- * Vertical placement of the `status` slot within the cell.
49
- *
50
- * - `true` (default) — the indicator is aligned to the **first line** of the
51
- * label and stays there when the label wraps or a `description` makes the
52
- * cell taller.
53
- * - `false` — the indicator is centred on the full height of the cell. This
54
- * restores the previous behaviour for consumers that depend on it.
55
- *
56
- * Has no effect when `status` is not provided.
57
- *
58
- * @default true
59
- */
47
+ /** Align `status` to the label's first line rather than the cell's full height. Defaults to `true`. */
60
48
  statusTopAlignment?: boolean;
61
49
  iconWrapper?: ReactNode;
62
50
  slot?: ReactNode;
@@ -73,20 +61,14 @@ interface ContextMenuOptionItemProps extends ContextMenuItemBaseProps {
73
61
  onSelect?: () => void;
74
62
  onCheckedChange?: (checked: boolean) => void;
75
63
  }
76
- /**
77
- * A search cell rendered at the top of the menu. When `searchable` is set on the
78
- * panel this cell is auto-rendered and stays mounted even when the query matches
79
- * nothing, so the user can clear it without reopening the menu. A trailing clear
80
- * (×) button appears whenever the field has a value; pressing it empties the
81
- * query (fires `onValueChange("")`) and refocuses the input.
82
- */
64
+ /** A search cell at the top of the menu; auto-rendered when `searchable` is set. */
83
65
  interface ContextMenuSearchItemProps extends ContextMenuItemBaseProps {
84
66
  type: "search";
85
67
  /** Controlled value of the search input. */
86
68
  value?: string;
87
69
  /** Raw change event; fires alongside `onValueChange`. */
88
70
  onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
89
- /** Change callback with the next string value. Also invoked with `""` when the clear button is pressed. */
71
+ /** Next string value. Also fires with `""` when the clear button is pressed. */
90
72
  onValueChange?: (value: string) => void;
91
73
  placeholder?: string;
92
74
  autoFocus?: boolean;
@@ -112,25 +94,11 @@ interface ContextMenuProps extends ThemeOverrideProps {
112
94
  emptyMessage?: string;
113
95
  empty?: ReactNode;
114
96
  trigger?: ReactNode;
115
- /**
116
- * When `true`, the trigger fills the full width of its parent instead of
117
- * shrinking to its content width. Defaults to `false`.
118
- */
97
+ /** Trigger fills its parent's width instead of hugging its content. Defaults to `false`. */
119
98
  triggerFullWidth?: boolean;
120
- /**
121
- * Menu placement relative to the trigger element. The `*-center` variants
122
- * horizontally center the panel on the trigger; every variant auto-flips on
123
- * the vertical axis (and `start`/`end` flip horizontally) when the menu
124
- * would clip the viewport. Only applies to trigger-anchored menus (ignored
125
- * when `position` is set). Defaults to `"bottom-start"`.
126
- */
99
+ /** Placement relative to the trigger; auto-flips to stay in the viewport. Ignored when `position` is set. Defaults to `"bottom-start"`. */
127
100
  placement?: ContextMenuPlacement;
128
- /**
129
- * Gap in pixels between the trigger and the menu. When `withArrow` is set
130
- * this is measured to the arrow's tip; otherwise to the panel edge. Only
131
- * applies to trigger-anchored menus (ignored when `position` is set).
132
- * Defaults to `4`.
133
- */
101
+ /** Gap in px to the panel edge, or to the arrow tip when `withArrow` is set. Defaults to `4`. */
134
102
  offset?: number;
135
103
  position?: ContextMenuPosition;
136
104
  isOpen?: boolean;
@@ -138,11 +106,7 @@ interface ContextMenuProps extends ThemeOverrideProps {
138
106
  closeOnSelect?: boolean;
139
107
  width?: number | string;
140
108
  maxHeight?: number;
141
- /**
142
- * Render a directional arrow on the panel edge pointing toward the trigger,
143
- * mirroring the Tooltip arrow. Only applies to trigger-anchored menus.
144
- * Defaults to `false`.
145
- */
109
+ /** Arrow on the panel edge pointing at the trigger. Defaults to `false`. */
146
110
  withArrow?: boolean;
147
111
  onSelect?: (item: ContextMenuOptionItemProps) => void;
148
112
  "aria-label"?: string;
@@ -151,15 +115,12 @@ interface ContextMenuProps extends ThemeOverrideProps {
151
115
  style?: CSSProperties;
152
116
  }
153
117
  interface ContextMenuSubmenuProps {
154
- /** Text label for the submenu trigger item */
155
118
  label: ReactNode;
156
- /** Leading icon for the trigger item */
157
119
  icon?: ReactNode;
158
- /** Whether the trigger item is disabled */
159
120
  disabled?: boolean;
160
121
  /** Submenu panel contents */
161
122
  children: ReactNode;
162
- /** Size inherited from parent */
123
+ /** Inherited from the parent menu when omitted */
163
124
  size?: ContextMenuSize;
164
125
  "data-testid"?: string;
165
126
  }
package/native/index.js CHANGED
@@ -728,11 +728,7 @@ var OptionCell = ({
728
728
  display: "inline-flex",
729
729
  alignItems: "center",
730
730
  flexShrink: 0,
731
- // Top alignment pins the slot to the top of the row and gives it
732
- // the height of one label line, so the dot centres on the FIRST
733
- // line and stays there when the label wraps or a `description`
734
- // pushes the row taller. Without it the row's `alignItems:center`
735
- // floats the dot to the middle of a multi-line cell.
731
+ // One label line tall, so the dot centres on that line when text wraps.
736
732
  ...statusTopAlignment ? { alignSelf: "flex-start", minHeight: labelLineHeight } : {}
737
733
  },
738
734
  children: status
@@ -834,8 +830,7 @@ var OptionCell = ({
834
830
  position: "fixed",
835
831
  top: submenuPos.top,
836
832
  left: submenuPos.left,
837
- // Same band as the parent menu; the submenu portal mounts later in
838
- // the DOM so it paints above it (holds for arbitrary nesting depth).
833
+ // Same band as the parent; later DOM order paints it above.
839
834
  zIndex: overlayLayer + import_xui_core.LAYER_OFFSET.menu
840
835
  },
841
836
  children: submenu
@@ -1199,9 +1194,7 @@ var ContextMenuSubmenu = ({
1199
1194
  top: pos ? pos.top : 0,
1200
1195
  // Hidden until measured to avoid a flash at (0,0).
1201
1196
  visibility: pos ? "visible" : "hidden",
1202
- // One step above the parent panel. The overlay-layer context flows
1203
- // through the portal, so a submenu inside a modal stays above panel and
1204
- // modal; nested submenus tie and DOM order resolves the stack.
1197
+ // One step above the parent panel; nested ties resolve by DOM order.
1205
1198
  zIndex: overlayLayer + import_xui_core2.LAYER_OFFSET.menu + 1,
1206
1199
  opacity: visible ? 1 : 0,
1207
1200
  transform: visible ? "translateX(0)" : openLeft ? "translateX(4px)" : "translateX(-4px)",
@@ -1467,6 +1460,15 @@ var ARROW_TIP_PROTRUSION = ARROW_HALF * Math.SQRT2;
1467
1460
  var PANEL_SHADOW = "0 4px 12px rgba(0,0,0,0.15)";
1468
1461
  var DROPDOWN_LAYER_SELECTOR = '[data-modal-id],[role="listbox"]';
1469
1462
  var ownLayerSelector = (menuId) => `${DROPDOWN_LAYER_SELECTOR},[data-xui-context-menu-portal="${menuId}"],[data-xui-context-menu-owner="${menuId}"]`;
1463
+ var isInOwnLayer = (event, selector) => {
1464
+ const path = typeof event.composedPath === "function" ? event.composedPath() : [];
1465
+ if (path.length)
1466
+ return path.some(
1467
+ (node) => node instanceof Element && node.matches(selector)
1468
+ );
1469
+ const target = event.target;
1470
+ return target instanceof Element && !!target.closest(selector);
1471
+ };
1470
1472
  var textFromNode = (node) => {
1471
1473
  if (node === null || node === void 0 || typeof node === "boolean")
1472
1474
  return "";
@@ -1670,12 +1672,7 @@ var ContextMenuRoot = (0, import_react6.forwardRef)(
1670
1672
  const target = event.target;
1671
1673
  if (!target) return;
1672
1674
  if (containerRef.current?.contains(target)) return;
1673
- const selector = ownLayerSelector(menuId);
1674
- const path = typeof event.composedPath === "function" ? event.composedPath() : [];
1675
- const isInsidePortaledLayer = path.length ? path.some(
1676
- (node) => node instanceof Element && node.matches(selector)
1677
- ) : target instanceof Element && !!target.closest(selector);
1678
- if (isInsidePortaledLayer) return;
1675
+ if (isInOwnLayer(event, ownLayerSelector(menuId))) return;
1679
1676
  closeMenu();
1680
1677
  };
1681
1678
  const onScroll = (event) => {
@@ -1683,6 +1680,7 @@ var ContextMenuRoot = (0, import_react6.forwardRef)(
1683
1680
  if (target instanceof Node && (containerRef.current?.contains(target) || panelRef.current?.contains(target))) {
1684
1681
  return;
1685
1682
  }
1683
+ if (isInOwnLayer(event, ownLayerSelector(menuId))) return;
1686
1684
  closeMenu();
1687
1685
  };
1688
1686
  document.addEventListener("mousedown", onMouseDown);
@@ -1857,22 +1855,26 @@ var ContextMenuRoot = (0, import_react6.forwardRef)(
1857
1855
  firstChild instanceof HTMLElement ? firstChild : node
1858
1856
  );
1859
1857
  };
1860
- const triggerNode = trigger && (0, import_react6.isValidElement)(trigger) ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1861
- "span",
1862
- {
1863
- ref: assignTriggerWrapperRef,
1864
- onClick: (event) => {
1865
- if (!event.defaultPrevented) toggleMenu();
1866
- },
1867
- style: {
1868
- display: "inline-flex",
1869
- width: triggerFullWidth ? "100%" : "auto"
1870
- },
1871
- children: (0, import_react6.cloneElement)(trigger, {
1872
- "aria-haspopup": "menu",
1873
- "aria-expanded": isOpen ? "true" : "false"
1874
- })
1875
- }
1858
+ const triggerNode = trigger && (0, import_react6.isValidElement)(trigger) ? (
1859
+ // Presentational click shim; the wrapped trigger owns keyboard activation.
1860
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1861
+ "span",
1862
+ {
1863
+ ref: assignTriggerWrapperRef,
1864
+ role: "presentation",
1865
+ onClick: (event) => {
1866
+ if (!event.defaultPrevented) toggleMenu();
1867
+ },
1868
+ style: {
1869
+ display: "inline-flex",
1870
+ width: triggerFullWidth ? "100%" : "auto"
1871
+ },
1872
+ children: (0, import_react6.cloneElement)(trigger, {
1873
+ "aria-haspopup": "menu",
1874
+ "aria-expanded": isOpen ? "true" : "false"
1875
+ })
1876
+ }
1877
+ )
1876
1878
  ) : trigger ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1877
1879
  "span",
1878
1880
  {
@@ -1882,6 +1884,11 @@ var ContextMenuRoot = (0, import_react6.forwardRef)(
1882
1884
  "aria-haspopup": "menu",
1883
1885
  "aria-expanded": isOpen ? "true" : "false",
1884
1886
  onClick: toggleMenu,
1887
+ onKeyDown: (event) => {
1888
+ if (event.key !== "Enter" && event.key !== " ") return;
1889
+ event.preventDefault();
1890
+ toggleMenu();
1891
+ },
1885
1892
  children: trigger
1886
1893
  }
1887
1894
  ) : null;