@xsolla/xui-context-menu 0.225.0 → 0.227.0

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.js CHANGED
@@ -1554,6 +1554,7 @@ var filterItems = (items, query) => {
1554
1554
  return result;
1555
1555
  };
1556
1556
  var isOption = (item) => item.type === "option";
1557
+ var isSearchCellElement = (node) => (0, import_react8.isValidElement)(node) && node.type === ContextMenuItem && node.props.type === "search";
1557
1558
  var ContextMenuRoot = (0, import_react8.forwardRef)(
1558
1559
  ({
1559
1560
  children,
@@ -1830,7 +1831,7 @@ var ContextMenuRoot = (0, import_react8.forwardRef)(
1830
1831
  );
1831
1832
  };
1832
1833
  const renderedItems = searchable ? filterItems(items, debouncedQuery) : [...items];
1833
- const searchHeader = searchable ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1834
+ const renderStickySearch = (node, key) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1834
1835
  "div",
1835
1836
  {
1836
1837
  "data-sticky": "top",
@@ -1840,21 +1841,34 @@ var ContextMenuRoot = (0, import_react8.forwardRef)(
1840
1841
  zIndex: 1,
1841
1842
  backgroundColor: surfaceColor
1842
1843
  },
1843
- children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1844
- ContextMenuItem,
1845
- {
1846
- type: "search",
1847
- value: query,
1848
- onValueChange: setQuery,
1849
- placeholder: "Search",
1850
- autoFocus: true,
1851
- themeMode,
1852
- themeProductContext
1853
- }
1854
- )
1844
+ children: node
1855
1845
  },
1846
+ key
1847
+ );
1848
+ const searchHeader = searchable ? renderStickySearch(
1849
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1850
+ ContextMenuItem,
1851
+ {
1852
+ type: "search",
1853
+ value: query,
1854
+ onValueChange: setQuery,
1855
+ placeholder: "Search",
1856
+ autoFocus: true,
1857
+ themeMode,
1858
+ themeProductContext
1859
+ }
1860
+ ),
1856
1861
  "context-menu-search"
1857
1862
  ) : null;
1863
+ const renderChildren = () => {
1864
+ if (!import_react8.default.Children.toArray(children).some(isSearchCellElement)) {
1865
+ return children;
1866
+ }
1867
+ return import_react8.default.Children.map(
1868
+ children,
1869
+ (child, index2) => isSearchCellElement(child) ? renderStickySearch(child, `context-menu-search-${index2}`) : child
1870
+ );
1871
+ };
1858
1872
  const renderContent = () => {
1859
1873
  if (loading || isLoading || type === "loading") {
1860
1874
  const brandColor = xuiTheme.colors.control.brand.primary.bg;
@@ -1869,7 +1883,7 @@ var ContextMenuRoot = (0, import_react8.forwardRef)(
1869
1883
  }
1870
1884
  );
1871
1885
  }
1872
- if (children) return children;
1886
+ if (children) return renderChildren();
1873
1887
  if (renderedItems.length === 0) {
1874
1888
  const emptyNode = empty ?? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1875
1889
  "div",