@xsolla/xui-context-menu 0.185.1 → 0.185.2

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
@@ -459,13 +459,16 @@ var OptionCell = ({
459
459
  const inOption = optionRef.current?.contains(target);
460
460
  const inSubmenu = submenuWrapperRef.current?.contains(target);
461
461
  if (!inOption && !inSubmenu) {
462
+ if (target.closest("[data-xui-context-menu-portal]")) return;
462
463
  setSubmenuOpen(false);
463
464
  return;
464
465
  }
465
- if (inSubmenu && target.closest(
466
- '[role="menuitem"],[role="menuitemcheckbox"],[role="menuitemradio"]'
467
- )) {
468
- setSubmenuOpen(false);
466
+ if (inSubmenu) {
467
+ const activated = target.closest(
468
+ '[role="menuitem"],[role="menuitemcheckbox"],[role="menuitemradio"]'
469
+ );
470
+ const isLeafAction = activated?.getAttribute("role") === "menuitem" && activated.getAttribute("aria-haspopup") !== "menu";
471
+ if (isLeafAction) setSubmenuOpen(false);
469
472
  }
470
473
  };
471
474
  document.addEventListener("mousedown", onMouseDown);
@@ -1359,6 +1362,7 @@ var ARROW_HALF = ARROW_SIZE / 2;
1359
1362
  var ARROW_EDGE_OFFSET = 12;
1360
1363
  var ARROW_TIP_PROTRUSION = ARROW_HALF * Math.SQRT2;
1361
1364
  var PANEL_SHADOW = "0 4px 12px rgba(0,0,0,0.15)";
1365
+ var PORTALED_LAYER_SELECTOR = '[data-modal-id],[role="listbox"],[data-xui-context-menu-portal]';
1362
1366
  var textFromNode = (node) => {
1363
1367
  if (node === null || node === void 0 || typeof node === "boolean")
1364
1368
  return "";
@@ -1545,7 +1549,13 @@ var ContextMenuRoot = forwardRef(
1545
1549
  if (!isOpen || !trigger) return;
1546
1550
  const onMouseDown = (event) => {
1547
1551
  const target = event.target;
1548
- if (!target || containerRef.current?.contains(target)) return;
1552
+ if (!target) return;
1553
+ if (containerRef.current?.contains(target)) return;
1554
+ const path = typeof event.composedPath === "function" ? event.composedPath() : [];
1555
+ const isInsidePortaledLayer = path.length ? path.some(
1556
+ (node) => node instanceof Element && node.matches(PORTALED_LAYER_SELECTOR)
1557
+ ) : target instanceof Element && !!target.closest(PORTALED_LAYER_SELECTOR);
1558
+ if (isInsidePortaledLayer) return;
1549
1559
  closeMenu();
1550
1560
  };
1551
1561
  const onScroll = () => closeMenu();