@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/web/index.mjs CHANGED
@@ -729,11 +729,7 @@ var OptionCell = ({
729
729
  display: "inline-flex",
730
730
  alignItems: "center",
731
731
  flexShrink: 0,
732
- // Top alignment pins the slot to the top of the row and gives it
733
- // the height of one label line, so the dot centres on the FIRST
734
- // line and stays there when the label wraps or a `description`
735
- // pushes the row taller. Without it the row's `alignItems:center`
736
- // floats the dot to the middle of a multi-line cell.
732
+ // One label line tall, so the dot centres on that line when text wraps.
737
733
  ...statusTopAlignment ? { alignSelf: "flex-start", minHeight: labelLineHeight } : {}
738
734
  },
739
735
  children: status
@@ -835,8 +831,7 @@ var OptionCell = ({
835
831
  position: "fixed",
836
832
  top: submenuPos.top,
837
833
  left: submenuPos.left,
838
- // Same band as the parent menu; the submenu portal mounts later in
839
- // the DOM so it paints above it (holds for arbitrary nesting depth).
834
+ // Same band as the parent; later DOM order paints it above.
840
835
  zIndex: overlayLayer + LAYER_OFFSET.menu
841
836
  },
842
837
  children: submenu
@@ -1210,9 +1205,7 @@ var ContextMenuSubmenu = ({
1210
1205
  top: pos ? pos.top : 0,
1211
1206
  // Hidden until measured to avoid a flash at (0,0).
1212
1207
  visibility: pos ? "visible" : "hidden",
1213
- // One step above the parent panel. The overlay-layer context flows
1214
- // through the portal, so a submenu inside a modal stays above panel and
1215
- // modal; nested submenus tie and DOM order resolves the stack.
1208
+ // One step above the parent panel; nested ties resolve by DOM order.
1216
1209
  zIndex: overlayLayer + LAYER_OFFSET2.menu + 1,
1217
1210
  opacity: visible ? 1 : 0,
1218
1211
  transform: visible ? "translateX(0)" : openLeft ? "translateX(4px)" : "translateX(-4px)",
@@ -1478,6 +1471,15 @@ var ARROW_TIP_PROTRUSION = ARROW_HALF * Math.SQRT2;
1478
1471
  var PANEL_SHADOW = "0 4px 12px rgba(0,0,0,0.15)";
1479
1472
  var DROPDOWN_LAYER_SELECTOR = '[data-modal-id],[role="listbox"]';
1480
1473
  var ownLayerSelector = (menuId) => `${DROPDOWN_LAYER_SELECTOR},[data-xui-context-menu-portal="${menuId}"],[data-xui-context-menu-owner="${menuId}"]`;
1474
+ var isInOwnLayer = (event, selector) => {
1475
+ const path = typeof event.composedPath === "function" ? event.composedPath() : [];
1476
+ if (path.length)
1477
+ return path.some(
1478
+ (node) => node instanceof Element && node.matches(selector)
1479
+ );
1480
+ const target = event.target;
1481
+ return target instanceof Element && !!target.closest(selector);
1482
+ };
1481
1483
  var textFromNode = (node) => {
1482
1484
  if (node === null || node === void 0 || typeof node === "boolean")
1483
1485
  return "";
@@ -1681,12 +1683,7 @@ var ContextMenuRoot = forwardRef(
1681
1683
  const target = event.target;
1682
1684
  if (!target) return;
1683
1685
  if (containerRef.current?.contains(target)) return;
1684
- const selector = ownLayerSelector(menuId);
1685
- const path = typeof event.composedPath === "function" ? event.composedPath() : [];
1686
- const isInsidePortaledLayer = path.length ? path.some(
1687
- (node) => node instanceof Element && node.matches(selector)
1688
- ) : target instanceof Element && !!target.closest(selector);
1689
- if (isInsidePortaledLayer) return;
1686
+ if (isInOwnLayer(event, ownLayerSelector(menuId))) return;
1690
1687
  closeMenu();
1691
1688
  };
1692
1689
  const onScroll = (event) => {
@@ -1694,6 +1691,7 @@ var ContextMenuRoot = forwardRef(
1694
1691
  if (target instanceof Node && (containerRef.current?.contains(target) || panelRef.current?.contains(target))) {
1695
1692
  return;
1696
1693
  }
1694
+ if (isInOwnLayer(event, ownLayerSelector(menuId))) return;
1697
1695
  closeMenu();
1698
1696
  };
1699
1697
  document.addEventListener("mousedown", onMouseDown);
@@ -1868,22 +1866,26 @@ var ContextMenuRoot = forwardRef(
1868
1866
  firstChild instanceof HTMLElement ? firstChild : node
1869
1867
  );
1870
1868
  };
1871
- const triggerNode = trigger && isValidElement(trigger) ? /* @__PURE__ */ jsx4(
1872
- "span",
1873
- {
1874
- ref: assignTriggerWrapperRef,
1875
- onClick: (event) => {
1876
- if (!event.defaultPrevented) toggleMenu();
1877
- },
1878
- style: {
1879
- display: "inline-flex",
1880
- width: triggerFullWidth ? "100%" : "auto"
1881
- },
1882
- children: cloneElement(trigger, {
1883
- "aria-haspopup": "menu",
1884
- "aria-expanded": isOpen ? "true" : "false"
1885
- })
1886
- }
1869
+ const triggerNode = trigger && isValidElement(trigger) ? (
1870
+ // Presentational click shim; the wrapped trigger owns keyboard activation.
1871
+ /* @__PURE__ */ jsx4(
1872
+ "span",
1873
+ {
1874
+ ref: assignTriggerWrapperRef,
1875
+ role: "presentation",
1876
+ onClick: (event) => {
1877
+ if (!event.defaultPrevented) toggleMenu();
1878
+ },
1879
+ style: {
1880
+ display: "inline-flex",
1881
+ width: triggerFullWidth ? "100%" : "auto"
1882
+ },
1883
+ children: cloneElement(trigger, {
1884
+ "aria-haspopup": "menu",
1885
+ "aria-expanded": isOpen ? "true" : "false"
1886
+ })
1887
+ }
1888
+ )
1887
1889
  ) : trigger ? /* @__PURE__ */ jsx4(
1888
1890
  "span",
1889
1891
  {
@@ -1893,6 +1895,11 @@ var ContextMenuRoot = forwardRef(
1893
1895
  "aria-haspopup": "menu",
1894
1896
  "aria-expanded": isOpen ? "true" : "false",
1895
1897
  onClick: toggleMenu,
1898
+ onKeyDown: (event) => {
1899
+ if (event.key !== "Enter" && event.key !== " ") return;
1900
+ event.preventDefault();
1901
+ toggleMenu();
1902
+ },
1896
1903
  children: trigger
1897
1904
  }
1898
1905
  ) : null;