@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.
package/web/index.d.mts 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/web/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/web/index.js CHANGED
@@ -618,7 +618,7 @@ var OptionCell = ({
618
618
  if (hasSubmenu) scheduleClose();
619
619
  };
620
620
  const labelColor = disabled ? theme.colors.control.input.textDisable : destructive ? theme.colors.content.alert.primary : theme.colors.content.primary;
621
- const bg = inHoverState ? theme.colors.control.input.bgHover : "transparent";
621
+ const bg = checked ? theme.colors.overlay.brand : inHoverState ? theme.colors.overlay.mono : "transparent";
622
622
  const role = !hasSubmenu && checked !== void 0 ? leadingControl === "radio" ? "menuitemradio" : "menuitemcheckbox" : "menuitem";
623
623
  const ariaChecked = !hasSubmenu && checked !== void 0 ? checked ? "true" : "false" : void 0;
624
624
  const handleClick = () => {
@@ -751,11 +751,7 @@ var OptionCell = ({
751
751
  display: "inline-flex",
752
752
  alignItems: "center",
753
753
  flexShrink: 0,
754
- // Top alignment pins the slot to the top of the row and gives it
755
- // the height of one label line, so the dot centres on the FIRST
756
- // line and stays there when the label wraps or a `description`
757
- // pushes the row taller. Without it the row's `alignItems:center`
758
- // floats the dot to the middle of a multi-line cell.
754
+ // One label line tall, so the dot centres on that line when text wraps.
759
755
  ...statusTopAlignment ? { alignSelf: "flex-start", minHeight: labelLineHeight } : {}
760
756
  },
761
757
  children: status
@@ -857,8 +853,7 @@ var OptionCell = ({
857
853
  position: "fixed",
858
854
  top: submenuPos.top,
859
855
  left: submenuPos.left,
860
- // Same band as the parent menu; the submenu portal mounts later in
861
- // the DOM so it paints above it (holds for arbitrary nesting depth).
856
+ // Same band as the parent; later DOM order paints it above.
862
857
  zIndex: overlayLayer + import_xui_core.LAYER_OFFSET.menu
863
858
  },
864
859
  children: submenu
@@ -1222,9 +1217,7 @@ var ContextMenuSubmenu = ({
1222
1217
  top: pos ? pos.top : 0,
1223
1218
  // Hidden until measured to avoid a flash at (0,0).
1224
1219
  visibility: pos ? "visible" : "hidden",
1225
- // One step above the parent panel. The overlay-layer context flows
1226
- // through the portal, so a submenu inside a modal stays above panel and
1227
- // modal; nested submenus tie and DOM order resolves the stack.
1220
+ // One step above the parent panel; nested ties resolve by DOM order.
1228
1221
  zIndex: overlayLayer + import_xui_core2.LAYER_OFFSET.menu + 1,
1229
1222
  opacity: visible ? 1 : 0,
1230
1223
  transform: visible ? "translateX(0)" : openLeft ? "translateX(4px)" : "translateX(-4px)",
@@ -1240,6 +1233,7 @@ var ContextMenuSubmenu = ({
1240
1233
  borderWidth: 1,
1241
1234
  borderRadius,
1242
1235
  paddingVertical: sizeStyles.paddingVertical,
1236
+ paddingHorizontal: sizeStyles.paddingHorizontal,
1243
1237
  style: {
1244
1238
  boxShadow: "0 4px 12px rgba(0,0,0,0.15)",
1245
1239
  minWidth: sizeStyles.minWidth
@@ -1490,6 +1484,15 @@ var ARROW_TIP_PROTRUSION = ARROW_HALF * Math.SQRT2;
1490
1484
  var PANEL_SHADOW = "0 4px 12px rgba(0,0,0,0.15)";
1491
1485
  var DROPDOWN_LAYER_SELECTOR = '[data-modal-id],[role="listbox"]';
1492
1486
  var ownLayerSelector = (menuId) => `${DROPDOWN_LAYER_SELECTOR},[data-xui-context-menu-portal="${menuId}"],[data-xui-context-menu-owner="${menuId}"]`;
1487
+ var isInOwnLayer = (event, selector) => {
1488
+ const path = typeof event.composedPath === "function" ? event.composedPath() : [];
1489
+ if (path.length)
1490
+ return path.some(
1491
+ (node) => node instanceof Element && node.matches(selector)
1492
+ );
1493
+ const target = event.target;
1494
+ return target instanceof Element && !!target.closest(selector);
1495
+ };
1493
1496
  var textFromNode = (node) => {
1494
1497
  if (node === null || node === void 0 || typeof node === "boolean")
1495
1498
  return "";
@@ -1693,12 +1696,7 @@ var ContextMenuRoot = (0, import_react8.forwardRef)(
1693
1696
  const target = event.target;
1694
1697
  if (!target) return;
1695
1698
  if (containerRef.current?.contains(target)) return;
1696
- const selector = ownLayerSelector(menuId);
1697
- const path = typeof event.composedPath === "function" ? event.composedPath() : [];
1698
- const isInsidePortaledLayer = path.length ? path.some(
1699
- (node) => node instanceof Element && node.matches(selector)
1700
- ) : target instanceof Element && !!target.closest(selector);
1701
- if (isInsidePortaledLayer) return;
1699
+ if (isInOwnLayer(event, ownLayerSelector(menuId))) return;
1702
1700
  closeMenu();
1703
1701
  };
1704
1702
  const onScroll = (event) => {
@@ -1706,6 +1704,7 @@ var ContextMenuRoot = (0, import_react8.forwardRef)(
1706
1704
  if (target instanceof Node && (containerRef.current?.contains(target) || panelRef.current?.contains(target))) {
1707
1705
  return;
1708
1706
  }
1707
+ if (isInOwnLayer(event, ownLayerSelector(menuId))) return;
1709
1708
  closeMenu();
1710
1709
  };
1711
1710
  document.addEventListener("mousedown", onMouseDown);
@@ -1880,22 +1879,26 @@ var ContextMenuRoot = (0, import_react8.forwardRef)(
1880
1879
  firstChild instanceof HTMLElement ? firstChild : node
1881
1880
  );
1882
1881
  };
1883
- const triggerNode = trigger && (0, import_react8.isValidElement)(trigger) ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1884
- "span",
1885
- {
1886
- ref: assignTriggerWrapperRef,
1887
- onClick: (event) => {
1888
- if (!event.defaultPrevented) toggleMenu();
1889
- },
1890
- style: {
1891
- display: "inline-flex",
1892
- width: triggerFullWidth ? "100%" : "auto"
1893
- },
1894
- children: (0, import_react8.cloneElement)(trigger, {
1895
- "aria-haspopup": "menu",
1896
- "aria-expanded": isOpen ? "true" : "false"
1897
- })
1898
- }
1882
+ const triggerNode = trigger && (0, import_react8.isValidElement)(trigger) ? (
1883
+ // Presentational click shim; the wrapped trigger owns keyboard activation.
1884
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1885
+ "span",
1886
+ {
1887
+ ref: assignTriggerWrapperRef,
1888
+ role: "presentation",
1889
+ onClick: (event) => {
1890
+ if (!event.defaultPrevented) toggleMenu();
1891
+ },
1892
+ style: {
1893
+ display: "inline-flex",
1894
+ width: triggerFullWidth ? "100%" : "auto"
1895
+ },
1896
+ children: (0, import_react8.cloneElement)(trigger, {
1897
+ "aria-haspopup": "menu",
1898
+ "aria-expanded": isOpen ? "true" : "false"
1899
+ })
1900
+ }
1901
+ )
1899
1902
  ) : trigger ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1900
1903
  "span",
1901
1904
  {
@@ -1905,6 +1908,11 @@ var ContextMenuRoot = (0, import_react8.forwardRef)(
1905
1908
  "aria-haspopup": "menu",
1906
1909
  "aria-expanded": isOpen ? "true" : "false",
1907
1910
  onClick: toggleMenu,
1911
+ onKeyDown: (event) => {
1912
+ if (event.key !== "Enter" && event.key !== " ") return;
1913
+ event.preventDefault();
1914
+ toggleMenu();
1915
+ },
1908
1916
  children: trigger
1909
1917
  }
1910
1918
  ) : null;
@@ -1945,6 +1953,7 @@ var ContextMenuRoot = (0, import_react8.forwardRef)(
1945
1953
  borderWidth: 1,
1946
1954
  borderRadius,
1947
1955
  paddingVertical: sizeStyles.paddingVertical,
1956
+ paddingHorizontal: sizeStyles.paddingHorizontal,
1948
1957
  width,
1949
1958
  minWidth: sizeStyles.minWidth,
1950
1959
  tabIndex: -1,
@@ -1959,7 +1968,9 @@ var ContextMenuRoot = (0, import_react8.forwardRef)(
1959
1968
  overflow: "visible"
1960
1969
  } : {
1961
1970
  maxHeight,
1962
- overflowY: "auto"
1971
+ overflowY: "auto",
1972
+ // Panel still scrolls; the bar itself is hidden.
1973
+ scrollbarWidth: "none"
1963
1974
  },
1964
1975
  outline: "none"
1965
1976
  },
@@ -1975,7 +1986,12 @@ var ContextMenuRoot = (0, import_react8.forwardRef)(
1975
1986
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1976
1987
  "div",
1977
1988
  {
1978
- style: { maxHeight, overflowY: "auto", borderRadius },
1989
+ style: {
1990
+ maxHeight,
1991
+ overflowY: "auto",
1992
+ scrollbarWidth: "none",
1993
+ borderRadius
1994
+ },
1979
1995
  children: renderContent()
1980
1996
  }
1981
1997
  )