@xsolla/xui-context-menu 0.202.2 → 0.202.4

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
  }
@@ -180,6 +141,7 @@ interface ContextMenuContextValue {
180
141
  }
181
142
  interface ContextMenuSizing {
182
143
  paddingVertical: number;
144
+ paddingHorizontal: number;
183
145
  itemPaddingHorizontal: number;
184
146
  itemPaddingVertical: number;
185
147
  fontSize: number;
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
  }
@@ -180,6 +141,7 @@ interface ContextMenuContextValue {
180
141
  }
181
142
  interface ContextMenuSizing {
182
143
  paddingVertical: number;
144
+ paddingHorizontal: number;
183
145
  itemPaddingHorizontal: number;
184
146
  itemPaddingVertical: number;
185
147
  fontSize: number;
package/native/index.js CHANGED
@@ -595,7 +595,7 @@ var OptionCell = ({
595
595
  if (hasSubmenu) scheduleClose();
596
596
  };
597
597
  const labelColor = disabled ? theme.colors.control.input.textDisable : destructive ? theme.colors.content.alert.primary : theme.colors.content.primary;
598
- const bg = inHoverState ? theme.colors.control.input.bgHover : "transparent";
598
+ const bg = checked ? theme.colors.overlay.brand : inHoverState ? theme.colors.overlay.mono : "transparent";
599
599
  const role = !hasSubmenu && checked !== void 0 ? leadingControl === "radio" ? "menuitemradio" : "menuitemcheckbox" : "menuitem";
600
600
  const ariaChecked = !hasSubmenu && checked !== void 0 ? checked ? "true" : "false" : void 0;
601
601
  const handleClick = () => {
@@ -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)",
@@ -1217,6 +1210,7 @@ var ContextMenuSubmenu = ({
1217
1210
  borderWidth: 1,
1218
1211
  borderRadius,
1219
1212
  paddingVertical: sizeStyles.paddingVertical,
1213
+ paddingHorizontal: sizeStyles.paddingHorizontal,
1220
1214
  style: {
1221
1215
  boxShadow: "0 4px 12px rgba(0,0,0,0.15)",
1222
1216
  minWidth: sizeStyles.minWidth
@@ -1467,6 +1461,15 @@ var ARROW_TIP_PROTRUSION = ARROW_HALF * Math.SQRT2;
1467
1461
  var PANEL_SHADOW = "0 4px 12px rgba(0,0,0,0.15)";
1468
1462
  var DROPDOWN_LAYER_SELECTOR = '[data-modal-id],[role="listbox"]';
1469
1463
  var ownLayerSelector = (menuId) => `${DROPDOWN_LAYER_SELECTOR},[data-xui-context-menu-portal="${menuId}"],[data-xui-context-menu-owner="${menuId}"]`;
1464
+ var isInOwnLayer = (event, selector) => {
1465
+ const path = typeof event.composedPath === "function" ? event.composedPath() : [];
1466
+ if (path.length)
1467
+ return path.some(
1468
+ (node) => node instanceof Element && node.matches(selector)
1469
+ );
1470
+ const target = event.target;
1471
+ return target instanceof Element && !!target.closest(selector);
1472
+ };
1470
1473
  var textFromNode = (node) => {
1471
1474
  if (node === null || node === void 0 || typeof node === "boolean")
1472
1475
  return "";
@@ -1670,12 +1673,7 @@ var ContextMenuRoot = (0, import_react6.forwardRef)(
1670
1673
  const target = event.target;
1671
1674
  if (!target) return;
1672
1675
  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;
1676
+ if (isInOwnLayer(event, ownLayerSelector(menuId))) return;
1679
1677
  closeMenu();
1680
1678
  };
1681
1679
  const onScroll = (event) => {
@@ -1683,6 +1681,7 @@ var ContextMenuRoot = (0, import_react6.forwardRef)(
1683
1681
  if (target instanceof Node && (containerRef.current?.contains(target) || panelRef.current?.contains(target))) {
1684
1682
  return;
1685
1683
  }
1684
+ if (isInOwnLayer(event, ownLayerSelector(menuId))) return;
1686
1685
  closeMenu();
1687
1686
  };
1688
1687
  document.addEventListener("mousedown", onMouseDown);
@@ -1857,22 +1856,26 @@ var ContextMenuRoot = (0, import_react6.forwardRef)(
1857
1856
  firstChild instanceof HTMLElement ? firstChild : node
1858
1857
  );
1859
1858
  };
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
- }
1859
+ const triggerNode = trigger && (0, import_react6.isValidElement)(trigger) ? (
1860
+ // Presentational click shim; the wrapped trigger owns keyboard activation.
1861
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1862
+ "span",
1863
+ {
1864
+ ref: assignTriggerWrapperRef,
1865
+ role: "presentation",
1866
+ onClick: (event) => {
1867
+ if (!event.defaultPrevented) toggleMenu();
1868
+ },
1869
+ style: {
1870
+ display: "inline-flex",
1871
+ width: triggerFullWidth ? "100%" : "auto"
1872
+ },
1873
+ children: (0, import_react6.cloneElement)(trigger, {
1874
+ "aria-haspopup": "menu",
1875
+ "aria-expanded": isOpen ? "true" : "false"
1876
+ })
1877
+ }
1878
+ )
1876
1879
  ) : trigger ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1877
1880
  "span",
1878
1881
  {
@@ -1882,6 +1885,11 @@ var ContextMenuRoot = (0, import_react6.forwardRef)(
1882
1885
  "aria-haspopup": "menu",
1883
1886
  "aria-expanded": isOpen ? "true" : "false",
1884
1887
  onClick: toggleMenu,
1888
+ onKeyDown: (event) => {
1889
+ if (event.key !== "Enter" && event.key !== " ") return;
1890
+ event.preventDefault();
1891
+ toggleMenu();
1892
+ },
1885
1893
  children: trigger
1886
1894
  }
1887
1895
  ) : null;
@@ -1922,6 +1930,7 @@ var ContextMenuRoot = (0, import_react6.forwardRef)(
1922
1930
  borderWidth: 1,
1923
1931
  borderRadius,
1924
1932
  paddingVertical: sizeStyles.paddingVertical,
1933
+ paddingHorizontal: sizeStyles.paddingHorizontal,
1925
1934
  width,
1926
1935
  minWidth: sizeStyles.minWidth,
1927
1936
  tabIndex: -1,
@@ -1936,7 +1945,9 @@ var ContextMenuRoot = (0, import_react6.forwardRef)(
1936
1945
  overflow: "visible"
1937
1946
  } : {
1938
1947
  maxHeight,
1939
- overflowY: "auto"
1948
+ overflowY: "auto",
1949
+ // Panel still scrolls; the bar itself is hidden.
1950
+ scrollbarWidth: "none"
1940
1951
  },
1941
1952
  outline: "none"
1942
1953
  },
@@ -1952,7 +1963,12 @@ var ContextMenuRoot = (0, import_react6.forwardRef)(
1952
1963
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1953
1964
  "div",
1954
1965
  {
1955
- style: { maxHeight, overflowY: "auto", borderRadius },
1966
+ style: {
1967
+ maxHeight,
1968
+ overflowY: "auto",
1969
+ scrollbarWidth: "none",
1970
+ borderRadius
1971
+ },
1956
1972
  children: renderContent()
1957
1973
  }
1958
1974
  )