@xsolla/xui-context-menu 0.211.1 → 0.212.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 +30 -0
- package/native/index.d.mts +11 -0
- package/native/index.d.ts +11 -0
- package/native/index.js +5 -3
- package/native/index.js.map +1 -1
- package/native/index.mjs +5 -3
- package/native/index.mjs.map +1 -1
- package/package.json +10 -10
- package/web/index.d.mts +11 -0
- package/web/index.d.ts +11 -0
- package/web/index.js +5 -3
- package/web/index.js.map +1 -1
- package/web/index.mjs +5 -3
- package/web/index.mjs.map +1 -1
package/README.md
CHANGED
|
@@ -29,6 +29,7 @@ A floating panel containing a vertical list of ContextMenuCell rows. Serves as t
|
|
|
29
29
|
- Trigger — the menu opens from a trigger element: right-click on a target, click on an overflow button (⋯), or programmatic call. The trigger element should have aria-haspopup=*"menu"* and aria-expanded updated on open/close.
|
|
30
30
|
- Positioning — the panel is positioned relative to the trigger. Default placement is bottom-start; fallback to top-start, bottom-end, or top-end when the default position would clip the viewport. Never let the panel appear partially off-screen.
|
|
31
31
|
- Width — the panel width is set by Size × Type. Do not stretch it to fill the viewport or a parent container. If option labels are longer than the panel width, truncate with ellipsis and show a tooltip on hover.
|
|
32
|
+
- Surface colour — the panel surface follows the theme by default. When a design calls for a bespoke surface, set it once via the background prop so the panel, the sticky search header and the arrow stay in sync. Do not tint the panel and the arrow separately.
|
|
32
33
|
- Single-select close — for Type=List, Phone, Avatar, BrandLogo, Status, and Radio, the menu closes automatically after the user selects an option. The trigger updates to reflect the new value.
|
|
33
34
|
- Multi-select stay open — for Type=Checkbox, the menu stays open after each selection. Close on: clicking outside, pressing Escape, or an explicit *"Apply"* / close action.
|
|
34
35
|
- Loading state — show Type=Loading immediately when the menu opens and the option list has not yet been fetched. The panel renders at its normal dimensions with a centered Loader spinner replacing all cell content. Switch to the real Type as soon as data arrives. Do not show an empty panel while loading.
|
|
@@ -50,6 +51,7 @@ A floating panel containing a vertical list of ContextMenuCell rows. Serves as t
|
|
|
50
51
|
- For sub-menus: → / Enter opens the sub-menu; ← / Escape closes it and returns focus to the parent item.
|
|
51
52
|
- When the menu closes, focus must return to the trigger element that opened it.
|
|
52
53
|
- For Type=Checkbox (multi-select), each option must have aria-checked=*"true"* / *"false"*. For Type=Radio and single-select list types, use aria-selected or aria-checked consistently with the chosen ARIA role.
|
|
54
|
+
- A custom surface set via background must keep at least a 4.5:1 contrast ratio against the option label colour, and the panel border must stay distinguishable from the surface behind it.
|
|
53
55
|
<!-- END:xui-mcp-instructions:context-menu -->
|
|
54
56
|
|
|
55
57
|
## Installation
|
|
@@ -194,6 +196,8 @@ A horizontal rule with `role="separator"`. No content props.
|
|
|
194
196
|
| `closeOnSelect` | `boolean` | Override the per-preset default. |
|
|
195
197
|
| `width` | `number` | Forces panel width (px). |
|
|
196
198
|
| `maxHeight` | `number` | Caps panel height (px); body scrolls and search stays sticky. |
|
|
199
|
+
| `withArrow` | `boolean` | Renders an arrow on the panel edge pointing at the trigger. Default `false`. |
|
|
200
|
+
| `background` | `string` | Panel surface colour (any CSS colour). Drives the panel, the sticky search header and the arrow together. Defaults to the `layer.float` theme token. |
|
|
197
201
|
| `noPadding` | `boolean` | Drops the panel's own padding (`8px` by default) to `0` so cells and custom children sit flush to its edges. Cell padding is unaffected. Defaults to `false`. |
|
|
198
202
|
| `onSelect` | `(item: ContextMenuOptionItemProps) => void` | Fires for the preset path on option activation. |
|
|
199
203
|
| `aria-label` | `string` | Accessible name for the menu container. |
|
|
@@ -213,6 +217,32 @@ The panel pads its own content by `8px` on every side at every `size`, so cells
|
|
|
213
217
|
|
|
214
218
|
`noPadding` only zeroes the **panel** padding. Each `ContextMenuItem` keeps its own `itemPaddingHorizontal` / `itemPaddingVertical`, so rows stay readable.
|
|
215
219
|
|
|
220
|
+
### Custom surface colour
|
|
221
|
+
|
|
222
|
+
The panel surface, the sticky search header and the `withArrow` arrow are three separate elements that all read the `layer.float` theme token. `background` resolves them from one value, so they can never drift apart.
|
|
223
|
+
|
|
224
|
+
```tsx
|
|
225
|
+
<ContextMenu
|
|
226
|
+
background="#233134"
|
|
227
|
+
withArrow
|
|
228
|
+
placement="bottom-center"
|
|
229
|
+
trigger={<Button>Open</Button>}
|
|
230
|
+
items={items}
|
|
231
|
+
/>
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
Use `background` rather than `style={{ backgroundColor }}`. `style` is merged onto the panel element only — the arrow keeps rendering in the theme colour and reads as a mismatched notch above the panel.
|
|
235
|
+
|
|
236
|
+
```tsx
|
|
237
|
+
// ✅ panel, sticky search header and arrow all tinted
|
|
238
|
+
<ContextMenu background="#233134" withArrow />
|
|
239
|
+
|
|
240
|
+
// ❌ panel tinted, arrow still on the theme token
|
|
241
|
+
<ContextMenu style={{ backgroundColor: "#233134" }} withArrow />
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
The prop takes any CSS colour string. Prefer a design token from your product theme over a literal hex where one exists, and check the label contrast — the toolkit cannot re-derive the content colours from a custom surface.
|
|
245
|
+
|
|
216
246
|
## Behaviour & accessibility
|
|
217
247
|
|
|
218
248
|
- The panel root is `role="menu"` (or hosts `role="menuitemcheckbox"` / `role="menuitemradio"` cells when `checked` is provided). Headings render as `role="presentation"`, dividers as `role="separator"`, and the search cell as `role="searchbox"`.
|
package/native/index.d.mts
CHANGED
|
@@ -112,6 +112,17 @@ interface ContextMenuProps extends ThemeOverrideProps {
|
|
|
112
112
|
withArrow?: boolean;
|
|
113
113
|
/** Drops the panel's own padding to `0` so cells and custom children sit flush to its edges. Cell padding is unaffected. Defaults to `false`. */
|
|
114
114
|
noPadding?: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Panel surface colour. Any CSS colour value.
|
|
117
|
+
*
|
|
118
|
+
* Applies to the panel background, the sticky search header and the
|
|
119
|
+
* `withArrow` arrow together, so the arrow can never be left on the theme
|
|
120
|
+
* token while the panel is tinted. Prefer this over `style.backgroundColor`,
|
|
121
|
+
* which reaches the panel only.
|
|
122
|
+
*
|
|
123
|
+
* Defaults to the `layer.float` theme token.
|
|
124
|
+
*/
|
|
125
|
+
background?: string;
|
|
115
126
|
onSelect?: (item: ContextMenuOptionItemProps) => void;
|
|
116
127
|
"aria-label"?: string;
|
|
117
128
|
testID?: string;
|
package/native/index.d.ts
CHANGED
|
@@ -112,6 +112,17 @@ interface ContextMenuProps extends ThemeOverrideProps {
|
|
|
112
112
|
withArrow?: boolean;
|
|
113
113
|
/** Drops the panel's own padding to `0` so cells and custom children sit flush to its edges. Cell padding is unaffected. Defaults to `false`. */
|
|
114
114
|
noPadding?: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Panel surface colour. Any CSS colour value.
|
|
117
|
+
*
|
|
118
|
+
* Applies to the panel background, the sticky search header and the
|
|
119
|
+
* `withArrow` arrow together, so the arrow can never be left on the theme
|
|
120
|
+
* token while the panel is tinted. Prefer this over `style.backgroundColor`,
|
|
121
|
+
* which reaches the panel only.
|
|
122
|
+
*
|
|
123
|
+
* Defaults to the `layer.float` theme token.
|
|
124
|
+
*/
|
|
125
|
+
background?: string;
|
|
115
126
|
onSelect?: (item: ContextMenuOptionItemProps) => void;
|
|
116
127
|
"aria-label"?: string;
|
|
117
128
|
testID?: string;
|
package/native/index.js
CHANGED
|
@@ -1527,6 +1527,7 @@ var ContextMenuRoot = (0, import_react6.forwardRef)(
|
|
|
1527
1527
|
maxHeight = 300,
|
|
1528
1528
|
withArrow = false,
|
|
1529
1529
|
noPadding = false,
|
|
1530
|
+
background,
|
|
1530
1531
|
onSelect,
|
|
1531
1532
|
closeOnSelect,
|
|
1532
1533
|
"aria-label": ariaLabel,
|
|
@@ -1561,6 +1562,7 @@ var ContextMenuRoot = (0, import_react6.forwardRef)(
|
|
|
1561
1562
|
const panelPaddingVertical = noPadding ? 0 : sizeStyles.paddingVertical;
|
|
1562
1563
|
const panelPaddingHorizontal = noPadding ? 0 : sizeStyles.paddingHorizontal;
|
|
1563
1564
|
const shouldCloseOnSelect = closeOnSelect ?? (type === "checkbox" ? false : true);
|
|
1565
|
+
const surfaceColor = background ?? xuiTheme.colors.layer.float;
|
|
1564
1566
|
const positionOffset = withArrow ? offset + ARROW_TIP_PROTRUSION : offset;
|
|
1565
1567
|
const positioned = useContextMenuPosition({
|
|
1566
1568
|
triggerRef,
|
|
@@ -1576,7 +1578,7 @@ var ContextMenuRoot = (0, import_react6.forwardRef)(
|
|
|
1576
1578
|
position: "absolute",
|
|
1577
1579
|
width: ARROW_SIZE,
|
|
1578
1580
|
height: ARROW_SIZE,
|
|
1579
|
-
backgroundColor:
|
|
1581
|
+
backgroundColor: surfaceColor,
|
|
1580
1582
|
borderStyle: "solid",
|
|
1581
1583
|
borderColor: xuiTheme.colors.border.secondary,
|
|
1582
1584
|
// 1px outline only on the two outward-facing edges of the rotated square
|
|
@@ -1787,7 +1789,7 @@ var ContextMenuRoot = (0, import_react6.forwardRef)(
|
|
|
1787
1789
|
position: "sticky",
|
|
1788
1790
|
top: 0,
|
|
1789
1791
|
zIndex: 1,
|
|
1790
|
-
backgroundColor:
|
|
1792
|
+
backgroundColor: surfaceColor
|
|
1791
1793
|
},
|
|
1792
1794
|
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1793
1795
|
ContextMenuItem,
|
|
@@ -1929,7 +1931,7 @@ var ContextMenuRoot = (0, import_react6.forwardRef)(
|
|
|
1929
1931
|
"data-testid": dataTestId ?? testID ?? "context-menu",
|
|
1930
1932
|
"data-xui-context-menu-portal": trigger || position ? menuId : void 0,
|
|
1931
1933
|
"data-placement": resolvedPlacement,
|
|
1932
|
-
backgroundColor:
|
|
1934
|
+
backgroundColor: surfaceColor,
|
|
1933
1935
|
borderColor: xuiTheme.colors.border.secondary,
|
|
1934
1936
|
borderWidth: 1,
|
|
1935
1937
|
borderRadius,
|