@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/README.md +15 -0
- package/native/index.js +28 -14
- package/native/index.js.map +1 -1
- package/native/index.mjs +28 -14
- package/native/index.mjs.map +1 -1
- package/package.json +10 -10
- package/web/index.js +28 -14
- package/web/index.js.map +1 -1
- package/web/index.mjs +28 -14
- package/web/index.mjs.map +1 -1
package/README.md
CHANGED
|
@@ -165,6 +165,21 @@ Every cell lays its slots out on a single centred row, which reads correctly whi
|
|
|
165
165
|
| `autoFocus` | `boolean` | Focuses the input on mount. |
|
|
166
166
|
| `aria-label` | `string` | Defaults to `"Search options"`. |
|
|
167
167
|
|
|
168
|
+
#### Pinned on scroll
|
|
169
|
+
|
|
170
|
+
When the option list overflows `maxHeight`, the search cell stays pinned to the top of the panel while the options scroll beneath it. This works on both API paths: the `searchable` preset, and a search cell passed as a **direct child** of `<ContextMenu>` on the custom path.
|
|
171
|
+
|
|
172
|
+
```tsx
|
|
173
|
+
<ContextMenu trigger={<Button>Select domain</Button>} maxHeight={240}>
|
|
174
|
+
<ContextMenuItem type="search" value={query} onValueChange={setQuery} />
|
|
175
|
+
{domains.map((domain) => (
|
|
176
|
+
<ContextMenuItem key={domain} type="option" label={domain} />
|
|
177
|
+
))}
|
|
178
|
+
</ContextMenu>
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
The panel detects the search cell among its direct children only. A search cell nested inside a fragment or your own wrapper component is not pinned — render it directly under `<ContextMenu>`.
|
|
182
|
+
|
|
168
183
|
### `type="heading"`
|
|
169
184
|
|
|
170
185
|
| Prop | Type | Purpose |
|
package/native/index.js
CHANGED
|
@@ -1524,6 +1524,7 @@ var filterItems = (items, query) => {
|
|
|
1524
1524
|
return result;
|
|
1525
1525
|
};
|
|
1526
1526
|
var isOption = (item) => item.type === "option";
|
|
1527
|
+
var isSearchCellElement = (node) => (0, import_react6.isValidElement)(node) && node.type === ContextMenuItem && node.props.type === "search";
|
|
1527
1528
|
var ContextMenuRoot = (0, import_react6.forwardRef)(
|
|
1528
1529
|
({
|
|
1529
1530
|
children,
|
|
@@ -1800,7 +1801,7 @@ var ContextMenuRoot = (0, import_react6.forwardRef)(
|
|
|
1800
1801
|
);
|
|
1801
1802
|
};
|
|
1802
1803
|
const renderedItems = searchable ? filterItems(items, debouncedQuery) : [...items];
|
|
1803
|
-
const
|
|
1804
|
+
const renderStickySearch = (node, key) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1804
1805
|
"div",
|
|
1805
1806
|
{
|
|
1806
1807
|
"data-sticky": "top",
|
|
@@ -1810,21 +1811,34 @@ var ContextMenuRoot = (0, import_react6.forwardRef)(
|
|
|
1810
1811
|
zIndex: 1,
|
|
1811
1812
|
backgroundColor: surfaceColor
|
|
1812
1813
|
},
|
|
1813
|
-
children:
|
|
1814
|
-
ContextMenuItem,
|
|
1815
|
-
{
|
|
1816
|
-
type: "search",
|
|
1817
|
-
value: query,
|
|
1818
|
-
onValueChange: setQuery,
|
|
1819
|
-
placeholder: "Search",
|
|
1820
|
-
autoFocus: true,
|
|
1821
|
-
themeMode,
|
|
1822
|
-
themeProductContext
|
|
1823
|
-
}
|
|
1824
|
-
)
|
|
1814
|
+
children: node
|
|
1825
1815
|
},
|
|
1816
|
+
key
|
|
1817
|
+
);
|
|
1818
|
+
const searchHeader = searchable ? renderStickySearch(
|
|
1819
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1820
|
+
ContextMenuItem,
|
|
1821
|
+
{
|
|
1822
|
+
type: "search",
|
|
1823
|
+
value: query,
|
|
1824
|
+
onValueChange: setQuery,
|
|
1825
|
+
placeholder: "Search",
|
|
1826
|
+
autoFocus: true,
|
|
1827
|
+
themeMode,
|
|
1828
|
+
themeProductContext
|
|
1829
|
+
}
|
|
1830
|
+
),
|
|
1826
1831
|
"context-menu-search"
|
|
1827
1832
|
) : null;
|
|
1833
|
+
const renderChildren = () => {
|
|
1834
|
+
if (!import_react6.default.Children.toArray(children).some(isSearchCellElement)) {
|
|
1835
|
+
return children;
|
|
1836
|
+
}
|
|
1837
|
+
return import_react6.default.Children.map(
|
|
1838
|
+
children,
|
|
1839
|
+
(child, index) => isSearchCellElement(child) ? renderStickySearch(child, `context-menu-search-${index}`) : child
|
|
1840
|
+
);
|
|
1841
|
+
};
|
|
1828
1842
|
const renderContent = () => {
|
|
1829
1843
|
if (loading || isLoading || type === "loading") {
|
|
1830
1844
|
const brandColor = xuiTheme.colors.control.brand.primary.bg;
|
|
@@ -1839,7 +1853,7 @@ var ContextMenuRoot = (0, import_react6.forwardRef)(
|
|
|
1839
1853
|
}
|
|
1840
1854
|
);
|
|
1841
1855
|
}
|
|
1842
|
-
if (children) return
|
|
1856
|
+
if (children) return renderChildren();
|
|
1843
1857
|
if (renderedItems.length === 0) {
|
|
1844
1858
|
const emptyNode = empty ?? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1845
1859
|
"div",
|