@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.
package/native/index.mjs CHANGED
@@ -710,11 +710,7 @@ var OptionCell = ({
710
710
  display: "inline-flex",
711
711
  alignItems: "center",
712
712
  flexShrink: 0,
713
- // Top alignment pins the slot to the top of the row and gives it
714
- // the height of one label line, so the dot centres on the FIRST
715
- // line and stays there when the label wraps or a `description`
716
- // pushes the row taller. Without it the row's `alignItems:center`
717
- // floats the dot to the middle of a multi-line cell.
713
+ // One label line tall, so the dot centres on that line when text wraps.
718
714
  ...statusTopAlignment ? { alignSelf: "flex-start", minHeight: labelLineHeight } : {}
719
715
  },
720
716
  children: status
@@ -816,8 +812,7 @@ var OptionCell = ({
816
812
  position: "fixed",
817
813
  top: submenuPos.top,
818
814
  left: submenuPos.left,
819
- // Same band as the parent menu; the submenu portal mounts later in
820
- // the DOM so it paints above it (holds for arbitrary nesting depth).
815
+ // Same band as the parent; later DOM order paints it above.
821
816
  zIndex: overlayLayer + LAYER_OFFSET.menu
822
817
  },
823
818
  children: submenu
@@ -1191,9 +1186,7 @@ var ContextMenuSubmenu = ({
1191
1186
  top: pos ? pos.top : 0,
1192
1187
  // Hidden until measured to avoid a flash at (0,0).
1193
1188
  visibility: pos ? "visible" : "hidden",
1194
- // One step above the parent panel. The overlay-layer context flows
1195
- // through the portal, so a submenu inside a modal stays above panel and
1196
- // modal; nested submenus tie and DOM order resolves the stack.
1189
+ // One step above the parent panel; nested ties resolve by DOM order.
1197
1190
  zIndex: overlayLayer + LAYER_OFFSET2.menu + 1,
1198
1191
  opacity: visible ? 1 : 0,
1199
1192
  transform: visible ? "translateX(0)" : openLeft ? "translateX(4px)" : "translateX(-4px)",
@@ -1459,6 +1452,15 @@ var ARROW_TIP_PROTRUSION = ARROW_HALF * Math.SQRT2;
1459
1452
  var PANEL_SHADOW = "0 4px 12px rgba(0,0,0,0.15)";
1460
1453
  var DROPDOWN_LAYER_SELECTOR = '[data-modal-id],[role="listbox"]';
1461
1454
  var ownLayerSelector = (menuId) => `${DROPDOWN_LAYER_SELECTOR},[data-xui-context-menu-portal="${menuId}"],[data-xui-context-menu-owner="${menuId}"]`;
1455
+ var isInOwnLayer = (event, selector) => {
1456
+ const path = typeof event.composedPath === "function" ? event.composedPath() : [];
1457
+ if (path.length)
1458
+ return path.some(
1459
+ (node) => node instanceof Element && node.matches(selector)
1460
+ );
1461
+ const target = event.target;
1462
+ return target instanceof Element && !!target.closest(selector);
1463
+ };
1462
1464
  var textFromNode = (node) => {
1463
1465
  if (node === null || node === void 0 || typeof node === "boolean")
1464
1466
  return "";
@@ -1662,12 +1664,7 @@ var ContextMenuRoot = forwardRef(
1662
1664
  const target = event.target;
1663
1665
  if (!target) return;
1664
1666
  if (containerRef.current?.contains(target)) return;
1665
- const selector = ownLayerSelector(menuId);
1666
- const path = typeof event.composedPath === "function" ? event.composedPath() : [];
1667
- const isInsidePortaledLayer = path.length ? path.some(
1668
- (node) => node instanceof Element && node.matches(selector)
1669
- ) : target instanceof Element && !!target.closest(selector);
1670
- if (isInsidePortaledLayer) return;
1667
+ if (isInOwnLayer(event, ownLayerSelector(menuId))) return;
1671
1668
  closeMenu();
1672
1669
  };
1673
1670
  const onScroll = (event) => {
@@ -1675,6 +1672,7 @@ var ContextMenuRoot = forwardRef(
1675
1672
  if (target instanceof Node && (containerRef.current?.contains(target) || panelRef.current?.contains(target))) {
1676
1673
  return;
1677
1674
  }
1675
+ if (isInOwnLayer(event, ownLayerSelector(menuId))) return;
1678
1676
  closeMenu();
1679
1677
  };
1680
1678
  document.addEventListener("mousedown", onMouseDown);
@@ -1849,22 +1847,26 @@ var ContextMenuRoot = forwardRef(
1849
1847
  firstChild instanceof HTMLElement ? firstChild : node
1850
1848
  );
1851
1849
  };
1852
- const triggerNode = trigger && isValidElement(trigger) ? /* @__PURE__ */ jsx4(
1853
- "span",
1854
- {
1855
- ref: assignTriggerWrapperRef,
1856
- onClick: (event) => {
1857
- if (!event.defaultPrevented) toggleMenu();
1858
- },
1859
- style: {
1860
- display: "inline-flex",
1861
- width: triggerFullWidth ? "100%" : "auto"
1862
- },
1863
- children: cloneElement(trigger, {
1864
- "aria-haspopup": "menu",
1865
- "aria-expanded": isOpen ? "true" : "false"
1866
- })
1867
- }
1850
+ const triggerNode = trigger && isValidElement(trigger) ? (
1851
+ // Presentational click shim; the wrapped trigger owns keyboard activation.
1852
+ /* @__PURE__ */ jsx4(
1853
+ "span",
1854
+ {
1855
+ ref: assignTriggerWrapperRef,
1856
+ role: "presentation",
1857
+ onClick: (event) => {
1858
+ if (!event.defaultPrevented) toggleMenu();
1859
+ },
1860
+ style: {
1861
+ display: "inline-flex",
1862
+ width: triggerFullWidth ? "100%" : "auto"
1863
+ },
1864
+ children: cloneElement(trigger, {
1865
+ "aria-haspopup": "menu",
1866
+ "aria-expanded": isOpen ? "true" : "false"
1867
+ })
1868
+ }
1869
+ )
1868
1870
  ) : trigger ? /* @__PURE__ */ jsx4(
1869
1871
  "span",
1870
1872
  {
@@ -1874,6 +1876,11 @@ var ContextMenuRoot = forwardRef(
1874
1876
  "aria-haspopup": "menu",
1875
1877
  "aria-expanded": isOpen ? "true" : "false",
1876
1878
  onClick: toggleMenu,
1879
+ onKeyDown: (event) => {
1880
+ if (event.key !== "Enter" && event.key !== " ") return;
1881
+ event.preventDefault();
1882
+ toggleMenu();
1883
+ },
1877
1884
  children: trigger
1878
1885
  }
1879
1886
  ) : null;