@xsolla/xui-context-menu 0.187.3 → 0.188.1

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
@@ -1,5 +1,5 @@
1
1
  // src/ContextMenu.tsx
2
- import {
2
+ import React3, {
3
3
  cloneElement,
4
4
  forwardRef,
5
5
  isValidElement,
@@ -10,6 +10,7 @@ import {
10
10
  useRef as useRef2,
11
11
  useState as useState4
12
12
  } from "react";
13
+ import { createPortal as createPortal3 } from "react-dom";
13
14
 
14
15
  // ../../foundation/primitives-native/src/Box.tsx
15
16
  import {
@@ -193,8 +194,8 @@ var Box = ({
193
194
  import {
194
195
  useResolvedTheme as useResolvedTheme2,
195
196
  useId as useId2,
196
- useOverlayLayer as useOverlayLayer2,
197
- LAYER_OFFSET as LAYER_OFFSET2,
197
+ useOverlayLayer as useOverlayLayer3,
198
+ LAYER_OFFSET as LAYER_OFFSET3,
198
199
  useModalStackDepth
199
200
  } from "@xsolla/xui-core";
200
201
  import { Spinner } from "@xsolla/xui-spinner";
@@ -228,7 +229,7 @@ import {
228
229
  import { Typography } from "@xsolla/xui-typography";
229
230
  import { Checkbox } from "@xsolla/xui-checkbox";
230
231
  import { Radio } from "@xsolla/xui-radio";
231
- import { Search } from "@xsolla/xui-icons-base";
232
+ import { Search, Remove } from "@xsolla/xui-icons-base";
232
233
  import { jsx as jsx2, jsxs } from "react/jsx-runtime";
233
234
  var sizeToVariants = {
234
235
  xl: { label: "bodyLg", description: "bodyLg", headingAccent: "bodyLgAccent" },
@@ -812,6 +813,19 @@ var SearchCell = ({
812
813
  registerCell(id, { type: "search" });
813
814
  return () => unregisterCell(id);
814
815
  }, [registerCell, unregisterCell, id]);
816
+ const inputRef = React.useRef(null);
817
+ const hasValue = (value ?? "") !== "";
818
+ const handleClear = () => {
819
+ onValueChange?.("");
820
+ if (onChange && inputRef.current) {
821
+ inputRef.current.value = "";
822
+ onChange({
823
+ target: inputRef.current,
824
+ currentTarget: inputRef.current
825
+ });
826
+ }
827
+ inputRef.current?.focus();
828
+ };
815
829
  return /* @__PURE__ */ jsx2(
816
830
  "div",
817
831
  {
@@ -845,7 +859,8 @@ var SearchCell = ({
845
859
  /* @__PURE__ */ jsx2(
846
860
  "input",
847
861
  {
848
- type: "search",
862
+ ref: inputRef,
863
+ type: "text",
849
864
  role: "searchbox",
850
865
  "aria-label": ariaLabel,
851
866
  placeholder,
@@ -869,6 +884,37 @@ var SearchCell = ({
869
884
  lineHeight: `${sizing.searchLineHeight}px`
870
885
  }
871
886
  }
887
+ ),
888
+ hasValue && /* @__PURE__ */ jsx2(
889
+ "button",
890
+ {
891
+ type: "button",
892
+ "aria-label": "Clear search",
893
+ "data-testid": "ctxmenu-search-clear",
894
+ onMouseDown: (e) => e.preventDefault(),
895
+ onClick: handleClear,
896
+ style: {
897
+ display: "inline-flex",
898
+ alignItems: "center",
899
+ justifyContent: "center",
900
+ flexShrink: 0,
901
+ padding: 0,
902
+ margin: 0,
903
+ border: "none",
904
+ background: "transparent",
905
+ cursor: "pointer",
906
+ color: theme.colors.control.input.placeholder
907
+ },
908
+ children: /* @__PURE__ */ jsx2(
909
+ Remove,
910
+ {
911
+ variant: "line",
912
+ size: sizing.searchIconSize,
913
+ color: theme.colors.control.input.placeholder,
914
+ "aria-hidden": true
915
+ }
916
+ )
917
+ }
872
918
  )
873
919
  ]
874
920
  }
@@ -913,9 +959,15 @@ import {
913
959
  useLayoutEffect as useLayoutEffect2,
914
960
  useCallback
915
961
  } from "react";
916
- import { useDesignSystem } from "@xsolla/xui-core";
962
+ import { createPortal as createPortal2 } from "react-dom";
963
+ import {
964
+ useDesignSystem,
965
+ useOverlayLayer as useOverlayLayer2,
966
+ LAYER_OFFSET as LAYER_OFFSET2
967
+ } from "@xsolla/xui-core";
917
968
  import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
918
969
  var SUBMENU_GAP2 = 4;
970
+ var VIEWPORT_PADDING = 8;
919
971
  var OPEN_DELAY_MS = 200;
920
972
  var CLOSE_GRACE_MS = 100;
921
973
  var _submenuIdCounter = 0;
@@ -929,6 +981,7 @@ var ContextMenuSubmenu = ({
929
981
  }) => {
930
982
  const { theme } = useDesignSystem();
931
983
  const xuiTheme = theme;
984
+ const overlayLayer = useOverlayLayer2();
932
985
  const context = useContextMenu();
933
986
  const size = propSize || context?.size || "md";
934
987
  const sizeStyles = xuiTheme.sizing.contextMenu(size);
@@ -941,7 +994,7 @@ var ContextMenuSubmenu = ({
941
994
  const [isOpen, setIsOpen] = useState2(false);
942
995
  const [visible, setVisible] = useState2(false);
943
996
  const [openLeft, setOpenLeft] = useState2(false);
944
- const [topOffset, setTopOffset] = useState2(0);
997
+ const [pos, setPos] = useState2(null);
945
998
  const triggerRef = useRef(null);
946
999
  const submenuRef = useRef(null);
947
1000
  const openTimerRef = useRef(null);
@@ -956,43 +1009,44 @@ var ContextMenuSubmenu = ({
956
1009
  setIsOpen(false);
957
1010
  }
958
1011
  }, [context?.activeSubmenuId, submenuId]);
959
- const calculatePlacement = useCallback(() => {
960
- if (!triggerRef.current) return;
961
- const triggerRect = triggerRef.current.getBoundingClientRect();
962
- const estimatedWidth = sizeStyles.minWidth + 32;
963
- const wouldOverflowRight = triggerRect.right + estimatedWidth + SUBMENU_GAP2 > window.innerWidth - 8;
964
- const hasSpaceOnLeft = triggerRect.left - SUBMENU_GAP2 - estimatedWidth >= 8;
965
- setOpenLeft(wouldOverflowRight && hasSpaceOnLeft);
966
- setTopOffset(0);
967
- }, [sizeStyles.minWidth]);
968
1012
  useLayoutEffect2(() => {
969
- if (!isOpen || !submenuRef.current || !triggerRef.current) return;
970
- const submenuRect = submenuRef.current.getBoundingClientRect();
971
- const triggerRect = triggerRef.current.getBoundingClientRect();
972
- const wouldOverflowRight = triggerRect.right + submenuRect.width + SUBMENU_GAP2 > window.innerWidth - 8;
973
- const hasSpaceOnLeft = triggerRect.left - SUBMENU_GAP2 - submenuRect.width >= 8;
974
- setOpenLeft(wouldOverflowRight && hasSpaceOnLeft);
975
- const overflowBottom = triggerRect.top + submenuRect.height - (window.innerHeight - 8);
976
- if (overflowBottom > 0) {
977
- setTopOffset(-Math.min(overflowBottom, triggerRect.top - 8));
978
- } else {
979
- setTopOffset(0);
1013
+ if (!isOpen) {
1014
+ setPos(null);
1015
+ return;
980
1016
  }
1017
+ const compute = () => {
1018
+ const trigger = triggerRef.current;
1019
+ const panel = submenuRef.current;
1020
+ if (!trigger || !panel) return;
1021
+ const triggerRect = trigger.getBoundingClientRect();
1022
+ const submenuRect = panel.getBoundingClientRect();
1023
+ const wouldOverflowRight = triggerRect.right + submenuRect.width + SUBMENU_GAP2 > window.innerWidth - VIEWPORT_PADDING;
1024
+ const hasSpaceOnLeft = triggerRect.left - SUBMENU_GAP2 - submenuRect.width >= VIEWPORT_PADDING;
1025
+ const nextOpenLeft = wouldOverflowRight && hasSpaceOnLeft;
1026
+ setOpenLeft(nextOpenLeft);
1027
+ const left = nextOpenLeft ? triggerRect.left - SUBMENU_GAP2 - submenuRect.width : triggerRect.right + SUBMENU_GAP2;
1028
+ const overflowBottom = triggerRect.top + submenuRect.height - (window.innerHeight - VIEWPORT_PADDING);
1029
+ const top = overflowBottom > 0 ? triggerRect.top - Math.min(overflowBottom, triggerRect.top - VIEWPORT_PADDING) : triggerRect.top;
1030
+ setPos({ left, top });
1031
+ };
1032
+ compute();
1033
+ const onResize = () => compute();
1034
+ window.addEventListener("resize", onResize);
1035
+ return () => window.removeEventListener("resize", onResize);
981
1036
  }, [isOpen]);
982
1037
  useEffect2(() => {
983
- if (!isOpen) {
1038
+ if (!isOpen || !pos) {
984
1039
  setVisible(false);
985
1040
  return;
986
1041
  }
987
1042
  const raf = requestAnimationFrame(() => setVisible(true));
988
1043
  return () => cancelAnimationFrame(raf);
989
- }, [isOpen]);
1044
+ }, [isOpen, pos]);
990
1045
  useEffect2(() => () => clearTimers(), [clearTimers]);
991
1046
  const handleTriggerEnter = () => {
992
1047
  if (disabled) return;
993
1048
  clearTimers();
994
1049
  openTimerRef.current = setTimeout(() => {
995
- calculatePlacement();
996
1050
  setIsOpen(true);
997
1051
  context?.setActiveSubmenuId(submenuId);
998
1052
  }, OPEN_DELAY_MS);
@@ -1016,7 +1070,47 @@ var ContextMenuSubmenu = ({
1016
1070
  }
1017
1071
  }, CLOSE_GRACE_MS);
1018
1072
  };
1019
- const submenuPositionStyle = openLeft ? { right: `calc(100% + ${SUBMENU_GAP2}px)` } : { left: `calc(100% + ${SUBMENU_GAP2}px)` };
1073
+ const submenuPanel = /* @__PURE__ */ jsx3(
1074
+ "div",
1075
+ {
1076
+ ref: submenuRef,
1077
+ "data-xui-context-menu-portal": submenuId,
1078
+ "data-xui-context-menu-owner": context?.menuId,
1079
+ onMouseEnter: handleSubmenuEnter,
1080
+ onMouseLeave: handleSubmenuLeave,
1081
+ style: {
1082
+ position: "fixed",
1083
+ left: pos ? pos.left : 0,
1084
+ top: pos ? pos.top : 0,
1085
+ // Hidden until measured to avoid a flash at (0,0).
1086
+ visibility: pos ? "visible" : "hidden",
1087
+ // One step above the parent panel. The overlay-layer context flows
1088
+ // through the portal, so a submenu inside a modal stays above panel and
1089
+ // modal; nested submenus tie and DOM order resolves the stack.
1090
+ zIndex: overlayLayer + LAYER_OFFSET2.menu + 1,
1091
+ opacity: visible ? 1 : 0,
1092
+ transform: visible ? "translateX(0)" : openLeft ? "translateX(4px)" : "translateX(-4px)",
1093
+ transition: "opacity 100ms ease, transform 100ms ease"
1094
+ },
1095
+ "data-testid": `${testId}-content`,
1096
+ children: /* @__PURE__ */ jsx3(
1097
+ Box,
1098
+ {
1099
+ role: "menu",
1100
+ backgroundColor: xuiTheme.colors.background.secondary,
1101
+ borderColor: xuiTheme.colors.border.secondary,
1102
+ borderWidth: 1,
1103
+ borderRadius,
1104
+ paddingVertical: sizeStyles.paddingVertical,
1105
+ style: {
1106
+ boxShadow: "0 4px 12px rgba(0,0,0,0.15)",
1107
+ minWidth: sizeStyles.minWidth
1108
+ },
1109
+ children
1110
+ }
1111
+ )
1112
+ }
1113
+ );
1020
1114
  return /* @__PURE__ */ jsxs2(
1021
1115
  "div",
1022
1116
  {
@@ -1038,40 +1132,7 @@ var ContextMenuSubmenu = ({
1038
1132
  "data-testid": `${testId}-trigger`
1039
1133
  }
1040
1134
  ),
1041
- isOpen && /* @__PURE__ */ jsx3(
1042
- "div",
1043
- {
1044
- ref: submenuRef,
1045
- onMouseEnter: handleSubmenuEnter,
1046
- onMouseLeave: handleSubmenuLeave,
1047
- style: {
1048
- position: "absolute",
1049
- top: topOffset,
1050
- ...submenuPositionStyle,
1051
- zIndex: 1001,
1052
- opacity: visible ? 1 : 0,
1053
- transform: visible ? "translateX(0)" : openLeft ? "translateX(4px)" : "translateX(-4px)",
1054
- transition: "opacity 100ms ease, transform 100ms ease"
1055
- },
1056
- "data-testid": `${testId}-content`,
1057
- children: /* @__PURE__ */ jsx3(
1058
- Box,
1059
- {
1060
- role: "menu",
1061
- backgroundColor: xuiTheme.colors.background.secondary,
1062
- borderColor: xuiTheme.colors.border.secondary,
1063
- borderWidth: 1,
1064
- borderRadius,
1065
- paddingVertical: sizeStyles.paddingVertical,
1066
- style: {
1067
- boxShadow: "0 4px 12px rgba(0,0,0,0.15)",
1068
- minWidth: sizeStyles.minWidth
1069
- },
1070
- children
1071
- }
1072
- )
1073
- }
1074
- )
1135
+ isOpen && typeof document !== "undefined" ? createPortal2(submenuPanel, document.body) : null
1075
1136
  ]
1076
1137
  }
1077
1138
  );
@@ -1088,7 +1149,6 @@ var joinPlacement = (vertical, horizontal) => `${vertical}-${horizontal}`;
1088
1149
  var useContextMenuPosition = ({
1089
1150
  triggerRef,
1090
1151
  panelRef,
1091
- containerRef,
1092
1152
  isOpen,
1093
1153
  placement = "bottom-start",
1094
1154
  offset = 4
@@ -1102,7 +1162,6 @@ var useContextMenuPosition = ({
1102
1162
  const compute = () => {
1103
1163
  const trigger = triggerRef.current;
1104
1164
  const panel = panelRef.current;
1105
- const container = containerRef.current;
1106
1165
  if (!trigger || !panel) return;
1107
1166
  const triggerRect = trigger.getBoundingClientRect();
1108
1167
  const panelRect = panel.getBoundingClientRect();
@@ -1142,15 +1201,6 @@ var useContextMenuPosition = ({
1142
1201
  }
1143
1202
  }
1144
1203
  }
1145
- if (container) {
1146
- const containerRect = container.getBoundingClientRect();
1147
- const cOffsetW = container.offsetWidth;
1148
- const cOffsetH = container.offsetHeight;
1149
- const scaleX = cOffsetW > 0 ? containerRect.width / cOffsetW : 1;
1150
- const scaleY = cOffsetH > 0 ? containerRect.height / cOffsetH : 1;
1151
- left = (left - containerRect.left) / (scaleX || 1);
1152
- top = (top - containerRect.top) / (scaleY || 1);
1153
- }
1154
1204
  const next = {
1155
1205
  top,
1156
1206
  left,
@@ -1166,7 +1216,7 @@ var useContextMenuPosition = ({
1166
1216
  return () => {
1167
1217
  window.removeEventListener("resize", onResize);
1168
1218
  };
1169
- }, [isOpen, placement, offset, triggerRef, panelRef, containerRef]);
1219
+ }, [isOpen, placement, offset, triggerRef, panelRef]);
1170
1220
  return resolved;
1171
1221
  };
1172
1222
 
@@ -1300,7 +1350,8 @@ var ARROW_HALF = ARROW_SIZE / 2;
1300
1350
  var ARROW_EDGE_OFFSET = 12;
1301
1351
  var ARROW_TIP_PROTRUSION = ARROW_HALF * Math.SQRT2;
1302
1352
  var PANEL_SHADOW = "0 4px 12px rgba(0,0,0,0.15)";
1303
- var PORTALED_LAYER_SELECTOR = '[data-modal-id],[role="listbox"],[data-xui-context-menu-portal]';
1353
+ var DROPDOWN_LAYER_SELECTOR = '[data-modal-id],[role="listbox"]';
1354
+ var ownLayerSelector = (menuId) => `${DROPDOWN_LAYER_SELECTOR},[data-xui-context-menu-portal="${menuId}"],[data-xui-context-menu-owner="${menuId}"]`;
1304
1355
  var textFromNode = (node) => {
1305
1356
  if (node === null || node === void 0 || typeof node === "boolean")
1306
1357
  return "";
@@ -1371,7 +1422,7 @@ var ContextMenuRoot = forwardRef(
1371
1422
  });
1372
1423
  const xuiTheme = rawTheme;
1373
1424
  const menuId = useId2();
1374
- const overlayLayer = useOverlayLayer2();
1425
+ const overlayLayer = useOverlayLayer3();
1375
1426
  const modalStackDepth = useModalStackDepth();
1376
1427
  const openModalDepthRef = useRef2(null);
1377
1428
  const [internalIsOpen, setInternalIsOpen] = useState4(false);
@@ -1392,7 +1443,6 @@ var ContextMenuRoot = forwardRef(
1392
1443
  const positioned = useContextMenuPosition({
1393
1444
  triggerRef,
1394
1445
  panelRef,
1395
- containerRef,
1396
1446
  isOpen: isOpen && !!trigger && !position,
1397
1447
  placement,
1398
1448
  offset: positionOffset
@@ -1505,10 +1555,11 @@ var ContextMenuRoot = forwardRef(
1505
1555
  const target = event.target;
1506
1556
  if (!target) return;
1507
1557
  if (containerRef.current?.contains(target)) return;
1558
+ const selector = ownLayerSelector(menuId);
1508
1559
  const path = typeof event.composedPath === "function" ? event.composedPath() : [];
1509
1560
  const isInsidePortaledLayer = path.length ? path.some(
1510
- (node) => node instanceof Element && node.matches(PORTALED_LAYER_SELECTOR)
1511
- ) : target instanceof Element && !!target.closest(PORTALED_LAYER_SELECTOR);
1561
+ (node) => node instanceof Element && node.matches(selector)
1562
+ ) : target instanceof Element && !!target.closest(selector);
1512
1563
  if (isInsidePortaledLayer) return;
1513
1564
  closeMenu();
1514
1565
  };
@@ -1519,7 +1570,7 @@ var ContextMenuRoot = forwardRef(
1519
1570
  document.removeEventListener("mousedown", onMouseDown);
1520
1571
  window.removeEventListener("scroll", onScroll);
1521
1572
  };
1522
- }, [isOpen, trigger, closeMenu]);
1573
+ }, [isOpen, trigger, closeMenu, menuId]);
1523
1574
  useLayoutEffect4(() => {
1524
1575
  if (!isOpen || !panelRef.current) return;
1525
1576
  const searchbox = panelRef.current.querySelector('[role="searchbox"]');
@@ -1604,6 +1655,31 @@ var ContextMenuRoot = forwardRef(
1604
1655
  );
1605
1656
  };
1606
1657
  const renderedItems = searchable ? filterItems(items, debouncedQuery) : [...items];
1658
+ const searchHeader = searchable ? /* @__PURE__ */ jsx4(
1659
+ "div",
1660
+ {
1661
+ "data-sticky": "top",
1662
+ style: {
1663
+ position: "sticky",
1664
+ top: 0,
1665
+ zIndex: 1,
1666
+ backgroundColor: xuiTheme.colors.background.secondary
1667
+ },
1668
+ children: /* @__PURE__ */ jsx4(
1669
+ ContextMenuItem,
1670
+ {
1671
+ type: "search",
1672
+ value: query,
1673
+ onValueChange: setQuery,
1674
+ placeholder: "Search",
1675
+ autoFocus: true,
1676
+ themeMode,
1677
+ themeProductContext
1678
+ }
1679
+ )
1680
+ },
1681
+ "context-menu-search"
1682
+ ) : null;
1607
1683
  const renderContent = () => {
1608
1684
  if (loading || isLoading || type === "loading") {
1609
1685
  const brandColor = xuiTheme.colors.control.brand.primary.bg;
@@ -1619,38 +1695,28 @@ var ContextMenuRoot = forwardRef(
1619
1695
  );
1620
1696
  }
1621
1697
  if (children) return children;
1622
- const content = renderedItems.map(renderPresetItem);
1623
- if (searchable) {
1624
- content.unshift(
1625
- /* @__PURE__ */ jsx4(
1626
- "div",
1627
- {
1628
- "data-sticky": "top",
1629
- style: {
1630
- position: "sticky",
1631
- top: 0,
1632
- zIndex: 1,
1633
- backgroundColor: xuiTheme.colors.background.secondary
1634
- },
1635
- children: /* @__PURE__ */ jsx4(
1636
- ContextMenuItem,
1637
- {
1638
- type: "search",
1639
- value: query,
1640
- onValueChange: setQuery,
1641
- placeholder: "Search",
1642
- autoFocus: true,
1643
- themeMode,
1644
- themeProductContext
1645
- }
1646
- )
1698
+ if (renderedItems.length === 0) {
1699
+ const emptyNode = empty ?? /* @__PURE__ */ jsx4(
1700
+ "div",
1701
+ {
1702
+ style: {
1703
+ padding: 16,
1704
+ textAlign: "center",
1705
+ color: xuiTheme.colors.content.tertiary
1647
1706
  },
1648
- "context-menu-search"
1649
- )
1707
+ children: emptyMessage
1708
+ },
1709
+ "context-menu-empty"
1650
1710
  );
1711
+ if (!searchHeader) return emptyNode;
1712
+ return [
1713
+ searchHeader,
1714
+ /* @__PURE__ */ jsx4(React3.Fragment, { children: emptyNode }, "context-menu-empty")
1715
+ ];
1651
1716
  }
1652
- if (content.length > (searchable ? 1 : 0)) return content;
1653
- return empty ?? /* @__PURE__ */ jsx4("div", { style: { padding: 16 }, children: emptyMessage });
1717
+ const content = renderedItems.map(renderPresetItem);
1718
+ if (searchHeader) content.unshift(searchHeader);
1719
+ return content;
1654
1720
  };
1655
1721
  const assignPanelRef = (node) => {
1656
1722
  panelRef.current = node;
@@ -1703,11 +1769,11 @@ var ContextMenuRoot = forwardRef(
1703
1769
  left: position.x,
1704
1770
  top: position.y
1705
1771
  } : trigger ? positioned ? {
1706
- position: "absolute",
1772
+ position: "fixed",
1707
1773
  left: positioned.left,
1708
1774
  top: positioned.top
1709
1775
  } : {
1710
- position: "absolute",
1776
+ position: "fixed",
1711
1777
  visibility: "hidden"
1712
1778
  } : void 0;
1713
1779
  return /* @__PURE__ */ jsx4(ContextMenuContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxs3(
@@ -1720,50 +1786,60 @@ var ContextMenuRoot = forwardRef(
1720
1786
  },
1721
1787
  children: [
1722
1788
  triggerNode,
1723
- isOpen && /* @__PURE__ */ jsx4(
1724
- Box,
1725
- {
1726
- ref: assignPanelRef,
1727
- role: "menu",
1728
- "aria-label": ariaLabel,
1729
- "data-testid": dataTestId ?? testID ?? "context-menu",
1730
- "data-placement": resolvedPlacement,
1731
- backgroundColor: xuiTheme.colors.background.secondary,
1732
- borderColor: xuiTheme.colors.border.secondary,
1733
- borderWidth: 1,
1734
- borderRadius,
1735
- paddingVertical: sizeStyles.paddingVertical,
1736
- width,
1737
- minWidth: sizeStyles.minWidth,
1738
- tabIndex: -1,
1739
- onKeyDown: keyboard.handleKeyDown,
1740
- onMouseLeave: () => setActiveIndex(-1),
1741
- style: {
1742
- ...positionStyle,
1743
- ...style,
1744
- zIndex: overlayLayer + LAYER_OFFSET2.menu,
1745
- boxShadow: PANEL_SHADOW,
1746
- ...withArrow ? {
1747
- overflow: "visible"
1748
- } : {
1749
- maxHeight,
1750
- overflowY: "auto"
1789
+ isOpen && (() => {
1790
+ const panelNode = /* @__PURE__ */ jsx4(
1791
+ Box,
1792
+ {
1793
+ ref: assignPanelRef,
1794
+ role: "menu",
1795
+ "aria-label": ariaLabel,
1796
+ "data-testid": dataTestId ?? testID ?? "context-menu",
1797
+ "data-xui-context-menu-portal": trigger || position ? menuId : void 0,
1798
+ "data-placement": resolvedPlacement,
1799
+ backgroundColor: xuiTheme.colors.background.secondary,
1800
+ borderColor: xuiTheme.colors.border.secondary,
1801
+ borderWidth: 1,
1802
+ borderRadius,
1803
+ paddingVertical: sizeStyles.paddingVertical,
1804
+ width,
1805
+ minWidth: sizeStyles.minWidth,
1806
+ tabIndex: -1,
1807
+ onKeyDown: keyboard.handleKeyDown,
1808
+ onMouseLeave: () => setActiveIndex(-1),
1809
+ style: {
1810
+ ...positionStyle,
1811
+ ...style,
1812
+ zIndex: overlayLayer + LAYER_OFFSET3.menu,
1813
+ boxShadow: PANEL_SHADOW,
1814
+ ...withArrow ? {
1815
+ overflow: "visible"
1816
+ } : {
1817
+ maxHeight,
1818
+ overflowY: "auto"
1819
+ },
1820
+ outline: "none"
1751
1821
  },
1752
- outline: "none"
1753
- },
1754
- children: withArrow ? /* @__PURE__ */ jsxs3(Fragment, { children: [
1755
- /* @__PURE__ */ jsx4(
1756
- "span",
1757
- {
1758
- "aria-hidden": "true",
1759
- "data-testid": "context-menu-arrow",
1760
- style: getArrowStyle(resolvedPlacement)
1761
- }
1762
- ),
1763
- /* @__PURE__ */ jsx4("div", { style: { maxHeight, overflowY: "auto", borderRadius }, children: renderContent() })
1764
- ] }) : renderContent()
1765
- }
1766
- )
1822
+ children: withArrow ? /* @__PURE__ */ jsxs3(Fragment, { children: [
1823
+ /* @__PURE__ */ jsx4(
1824
+ "span",
1825
+ {
1826
+ "aria-hidden": "true",
1827
+ "data-testid": "context-menu-arrow",
1828
+ style: getArrowStyle(resolvedPlacement)
1829
+ }
1830
+ ),
1831
+ /* @__PURE__ */ jsx4(
1832
+ "div",
1833
+ {
1834
+ style: { maxHeight, overflowY: "auto", borderRadius },
1835
+ children: renderContent()
1836
+ }
1837
+ )
1838
+ ] }) : renderContent()
1839
+ }
1840
+ );
1841
+ return trigger || position ? typeof document !== "undefined" ? createPortal3(panelNode, document.body) : null : panelNode;
1842
+ })()
1767
1843
  ]
1768
1844
  }
1769
1845
  ) });