@astryxdesign/core 0.7.1-canary.e199fa4 → 0.7.1-canary.e71c4e9

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.
Files changed (66) hide show
  1. package/dist/CommandPalette/CommandPalette.d.ts +6 -4
  2. package/dist/CommandPalette/CommandPalette.d.ts.map +1 -1
  3. package/dist/CommandPalette/CommandPalette.js +38 -20
  4. package/dist/CommandPalette/CommandPaletteEmpty.d.ts +4 -3
  5. package/dist/CommandPalette/CommandPaletteEmpty.d.ts.map +1 -1
  6. package/dist/CommandPalette/CommandPaletteEmpty.js +4 -3
  7. package/dist/CommandPalette/CommandPaletteInput.d.ts +5 -4
  8. package/dist/CommandPalette/CommandPaletteInput.d.ts.map +1 -1
  9. package/dist/CommandPalette/CommandPaletteInput.js +35 -18
  10. package/dist/CommandPalette/CommandPaletteList.d.ts +4 -2
  11. package/dist/CommandPalette/CommandPaletteList.d.ts.map +1 -1
  12. package/dist/CommandPalette/CommandPaletteList.js +9 -4
  13. package/dist/ContextMenu/ContextMenu.d.ts +3 -3
  14. package/dist/ContextMenu/ContextMenu.d.ts.map +1 -1
  15. package/dist/ContextMenu/ContextMenu.js +62 -48
  16. package/dist/DropdownMenu/DropdownMenu.d.ts.map +1 -1
  17. package/dist/DropdownMenu/DropdownMenu.js +140 -63
  18. package/dist/Layer/useLayerDismissal.d.ts +9 -9
  19. package/dist/Layer/useLayerDismissal.js +9 -9
  20. package/dist/MultiSelector/MultiSelector.d.ts +2 -1
  21. package/dist/MultiSelector/MultiSelector.d.ts.map +1 -1
  22. package/dist/Selector/Selector.d.ts +3 -3
  23. package/dist/i18n/generated-locales/en.generated.d.ts.map +1 -1
  24. package/dist/i18n/generated-locales/en.generated.js +1 -0
  25. package/dist/i18n/generated-locales/pseudo.generated.d.ts.map +1 -1
  26. package/dist/i18n/generated-locales/pseudo.generated.js +1 -0
  27. package/dist/utils/plainDate.d.ts.map +1 -1
  28. package/dist/utils/plainDate.js +14 -5
  29. package/locales/en.json +5 -1
  30. package/locales/pseudo.json +3 -0
  31. package/package.json +3 -3
  32. package/src/Chat/ChatComposerInput.spec.md +86 -50
  33. package/src/CommandPalette/CommandPalette.doc.mjs +31 -1
  34. package/src/CommandPalette/CommandPalette.spec.md +96 -47
  35. package/src/CommandPalette/CommandPalette.test.tsx +241 -2
  36. package/src/CommandPalette/CommandPalette.tsx +44 -20
  37. package/src/CommandPalette/CommandPaletteEmpty.tsx +4 -3
  38. package/src/CommandPalette/CommandPaletteInput.doc.mjs +61 -4
  39. package/src/CommandPalette/CommandPaletteInput.spec.md +215 -0
  40. package/src/CommandPalette/CommandPaletteInput.test.tsx +375 -51
  41. package/src/CommandPalette/CommandPaletteInput.tsx +74 -21
  42. package/src/CommandPalette/CommandPaletteItem.test.tsx +7 -0
  43. package/src/CommandPalette/CommandPaletteList.doc.mjs +3 -3
  44. package/src/CommandPalette/CommandPaletteList.spec.md +41 -36
  45. package/src/CommandPalette/CommandPaletteList.test.tsx +67 -0
  46. package/src/CommandPalette/CommandPaletteList.tsx +9 -4
  47. package/src/CommandPalette/__tests__/CommandPalette.a11y.chromium.spec.ts +599 -0
  48. package/src/ComplexSelector/ComplexSelector.doc.mjs +1 -1
  49. package/src/ContextMenu/ContextMenu.doc.mjs +6 -0
  50. package/src/ContextMenu/ContextMenu.spec.md +51 -53
  51. package/src/ContextMenu/ContextMenu.test.tsx +132 -1
  52. package/src/ContextMenu/ContextMenu.tsx +78 -48
  53. package/src/DropdownMenu/DropdownMenu.doc.mjs +2 -2
  54. package/src/DropdownMenu/DropdownMenu.spec.md +73 -47
  55. package/src/DropdownMenu/DropdownMenu.test.tsx +239 -23
  56. package/src/DropdownMenu/DropdownMenu.tsx +189 -79
  57. package/src/DropdownMenu/__tests__/MenuHeaderFooter.a11y.chromium.spec.ts +40 -5
  58. package/src/Layer/useLayerDismissal.ts +9 -9
  59. package/src/MultiSelector/MultiSelector.doc.mjs +2 -2
  60. package/src/MultiSelector/MultiSelector.tsx +2 -1
  61. package/src/Selector/Selector.doc.mjs +2 -2
  62. package/src/Selector/Selector.tsx +3 -3
  63. package/src/i18n/generated-locales/en.generated.ts +1 -0
  64. package/src/i18n/generated-locales/pseudo.generated.ts +1 -0
  65. package/src/utils/plainDate.test.ts +99 -0
  66. package/src/utils/plainDate.ts +23 -5
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @file CommandPalette.tsx
3
- * @input Uses React, Dialog, Layout, CommandPaletteContext, SearchSource, useCombobox, useAnnounce
3
+ * @input Uses React, Dialog, Layout, CommandPaletteContext, SearchSource,
4
+ * useCombobox, useAnnounce, useAnnounceRenderedText
4
5
  * @output Exports CommandPalette root component and props
5
6
  * @position Core root component; dialog shell with searchSource-driven items
6
7
  *
@@ -84,9 +85,10 @@ export interface CommandPaletteProps<T extends SearchableItem = SearchableItem>
84
85
  * Uses `searchSource` for all search logic — same interface as Typeahead.
85
86
  * For static lists, use `createStaticSource` from `@astryxdesign/core/Typeahead`.
86
87
  *
87
- * Keyboard navigation is handled by `useCombobox` from Selector,
88
- * ensuring consistent arrow key, Home/End, Enter, and Escape behavior
89
- * across all combobox-pattern components.
88
+ * Keyboard navigation is handled by `useCombobox` from Selector for arrows,
89
+ * PageUp/PageDown, and Enter. Home/End remain native caret keys. Modal Escape
90
+ * dismissal delegates to Dialog's shared layer stack so nested surfaces handle
91
+ * the first press.
90
92
  *
91
93
  * Input and footer are rendered by default — only pass them to replace the defaults.
92
94
  *
@@ -1 +1 @@
1
- {"version":3,"file":"CommandPalette.d.ts","sourceRoot":"","sources":["../../src/CommandPalette/CommandPalette.tsx"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AAEH,OAAO,EASL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAGf,OAAO,KAAK,EAAC,YAAY,EAAE,cAAc,EAAC,MAAM,cAAc,CAAC;AAU/D,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAI5C,MAAM,WAAW,mBA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AkB,CAAC,EAAE,SAAS,CAAC;IAE/B,mDAAmD;IACnD,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,8CAA8C;IAC9C,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAExC;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAExB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC7B;AAiID;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,cAAc,GAAG,cAAc,EAAE,EACxE,GAAG,EACH,MAAM,EACN,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,KAAK,EACL,MAAM,EACN,UAAU,EACV,eAAe,EAAE,wBAAwB,EACzC,kBAAkB,EAAE,2BAA2B,EAC/C,KAAK,EAAE,eAAe,EACtB,aAAa,EACb,KAAK,EAAE,cAAc,EACrB,KAAW,EACX,SAAe,EACf,GAAG,IAAI,EACR,EAAE,mBAAmB,CAAC,CAAC,CAAC,+BA2YxB;yBA5Ze,cAAc"}
@@ -4,7 +4,8 @@
4
4
 
5
5
  /**
6
6
  * @file CommandPalette.tsx
7
- * @input Uses React, Dialog, Layout, CommandPaletteContext, SearchSource, useCombobox, useAnnounce
7
+ * @input Uses React, Dialog, Layout, CommandPaletteContext, SearchSource,
8
+ * useCombobox, useAnnounce, useAnnounceRenderedText
8
9
  * @output Exports CommandPalette root component and props
9
10
  * @position Core root component; dialog shell with searchSource-driven items
10
11
  *
@@ -24,6 +25,7 @@ import { CommandPaletteInput } from "./CommandPaletteInput.js";
24
25
  import { CommandPaletteFooter } from "./CommandPaletteFooter.js";
25
26
  import { CommandPaletteEmpty } from "./CommandPaletteEmpty.js";
26
27
  import { useAnnounce } from "../hooks/useAnnounce.js";
28
+ import { useAnnounceRenderedText } from "../hooks/useAnnounceRenderedText.js";
27
29
  import { useTranslator } from "../i18n/index.js";
28
30
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
29
31
  function getGroup(item) {
@@ -145,9 +147,10 @@ function ItemRenderer({
145
147
  * Uses `searchSource` for all search logic — same interface as Typeahead.
146
148
  * For static lists, use `createStaticSource` from `@astryxdesign/core/Typeahead`.
147
149
  *
148
- * Keyboard navigation is handled by `useCombobox` from Selector,
149
- * ensuring consistent arrow key, Home/End, Enter, and Escape behavior
150
- * across all combobox-pattern components.
150
+ * Keyboard navigation is handled by `useCombobox` from Selector for arrows,
151
+ * PageUp/PageDown, and Enter. Home/End remain native caret keys. Modal Escape
152
+ * dismissal delegates to Dialog's shared layer stack so nested surfaces handle
153
+ * the first press.
151
154
  *
152
155
  * Input and footer are rendered by default — only pass them to replace the defaults.
153
156
  *
@@ -200,6 +203,7 @@ export function CommandPalette({
200
203
  const [optimisticResults, setOptimisticResults] = useOptimistic(searchResults);
201
204
  const isBusy = isPending;
202
205
  const searchVersionRef = useRef(0);
206
+ const emptyStateRef = useRef(null);
203
207
 
204
208
  // Announce search status to screen readers through the shared polite live
205
209
  // region (comboboxes-7 announce path, mirroring Selector / BaseTypeahead).
@@ -267,6 +271,10 @@ export function CommandPalette({
267
271
  const runSearch = useCallback(query => {
268
272
  searchSource.cancel?.();
269
273
  const version = ++searchVersionRef.current;
274
+ // A highlight belongs to the query that created it. Clear it before any
275
+ // optimistic narrowing so aria-activedescendant never shifts to a
276
+ // different command at the same index while the next result set loads.
277
+ combobox.setHighlightedIndex(-1);
270
278
  startTransition(async () => {
271
279
  const isBootstrap = query === '';
272
280
 
@@ -293,18 +301,12 @@ export function CommandPalette({
293
301
 
294
302
  // Announce the outcome from the search commit (not a reactive
295
303
  // effect), matching Selector / BaseTypeahead: exactly one
296
- // announcement per committed query, and the version check above
297
- // already discards stale keystrokes. Bootstrap stays silent — the
298
- // same role PowerSearch's mount guard plays — so opening the
299
- // palette announces nothing; clearing the query only clears any
300
- // lingering status text.
304
+ // announcement per committed non-empty query. Empty results are
305
+ // announced from their rendered content below so a caller-supplied
306
+ // ReactNode reaches assistive technology as written.
301
307
  if (isBootstrap) {
302
308
  announce('');
303
- } else if (items.length === 0) {
304
- announce(t('@astryx.commandPalette.noResultsFor', {
305
- query
306
- }));
307
- } else {
309
+ } else if (items.length > 0) {
308
310
  announce(t('@astryx.commandPalette.resultCount', {
309
311
  count: items.length
310
312
  }));
@@ -346,13 +348,18 @@ export function CommandPalette({
346
348
  }
347
349
  }, [isOpen]);
348
350
 
349
- // Wrap combobox's onKeyDown to intercept Escape (close palette) and
350
- // Enter on highlight (select + close), since we're not using combobox's
351
- // built-in open/close lifecycle.
351
+ // Wrap combobox's onKeyDown to preserve inline-preview Escape handling and
352
+ // select + close on Enter. Modal Escape stays unclaimed here so Dialog's
353
+ // shared dismissal stack can route it to the topmost surface.
352
354
  const handleKeyDown = useCallback(e => {
353
355
  if (e.key === 'Escape') {
354
- e.preventDefault();
355
- handleClose();
356
+ // Modal CommandPalette delegates Escape to Dialog's shared dismissal
357
+ // stack so a nested layer handles the first press. Inline previews do
358
+ // not join that stack, so preserve their local close behavior.
359
+ if (isInline) {
360
+ e.preventDefault();
361
+ handleClose();
362
+ }
356
363
  return;
357
364
  }
358
365
  if (e.key === 'Enter') {
@@ -366,12 +373,17 @@ export function CommandPalette({
366
373
  }
367
374
  return;
368
375
  }
376
+ // Home and End remain native caret-movement keys for this editable
377
+ // combobox. PageUp/PageDown provide first/last result navigation.
378
+ if (e.key === 'Home' || e.key === 'End') {
379
+ return;
380
+ }
369
381
  // Space should type in the input, not trigger selection
370
382
  if (e.key === ' ') {
371
383
  return;
372
384
  }
373
385
  combobox.onKeyDown(e);
374
- }, [combobox, handleClose, selectableItems, selectItem]);
386
+ }, [combobox, handleClose, isInline, selectableItems, selectItem]);
375
387
 
376
388
  // Hover highlight is owned here by a single delegated handler on the list
377
389
  // container: it routes to useCombobox's hover-aware path, which moves the
@@ -427,13 +439,19 @@ export function CommandPalette({
427
439
  // the empty state is never unmounted and re-added mid-search (which flashed).
428
440
  const showEmptyBootstrap = search === '' && optimisticResults.length === 0;
429
441
  const showEmptySearch = search !== '' && optimisticResults.length === 0;
442
+ // Announce only once the search settles: while it is pending, optimistic
443
+ // narrowing can empty the list before the source answers, which would
444
+ // speak "No results" early or wrongly.
445
+ useAnnounceRenderedText(emptyStateRef, showEmptySearch && !isPending, search);
430
446
  let listContent;
431
447
  if (showEmptyBootstrap) {
432
448
  listContent = /*#__PURE__*/_jsx(CommandPaletteEmpty, {
449
+ ref: emptyStateRef,
433
450
  children: emptyBootstrapText
434
451
  });
435
452
  } else if (showEmptySearch) {
436
453
  listContent = /*#__PURE__*/_jsx(CommandPaletteEmpty, {
454
+ ref: emptyStateRef,
437
455
  children: emptySearchText
438
456
  });
439
457
  } else {
@@ -12,13 +12,14 @@ export interface CommandPaletteEmptyProps extends BaseProps<HTMLDivElement> {
12
12
  * - `emptyBootstrapText`: no search term and bootstrap() returns nothing
13
13
  * - `emptySearchText`: a search query returned no results
14
14
  *
15
- * Can also be composed manually inside a custom render function.
15
+ * Can also be composed as a standalone empty result surface. Render actionable
16
+ * empty content outside listbox and option semantics.
16
17
  *
17
18
  * @example
18
19
  * ```
19
20
  * <CommandPalette
20
- * emptyBootstrapText={<CommandPaletteEmpty>Start typing to search</CommandPaletteEmpty>}
21
- * emptySearchText={<CommandPaletteEmpty>No results found</CommandPaletteEmpty>}
21
+ * emptyBootstrapText="Start typing to search"
22
+ * emptySearchText="No results found"
22
23
  * searchSource={source}
23
24
  * />
24
25
  * ```
@@ -1 +1 @@
1
- {"version":3,"file":"CommandPaletteEmpty.d.ts","sourceRoot":"","sources":["../../src/CommandPalette/CommandPaletteEmpty.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,EAAC,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAS5C,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAkB5C,MAAM,WAAW,wBAAyB,SAAQ,SAAS,CAAC,cAAc,CAAC;IACzE,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAChC,yCAAyC;IACzC,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,GAAG,EACH,QAAQ,EACR,MAAM,EACN,SAAS,EACT,KAAK,EACL,GAAG,KAAK,EACT,EAAE,wBAAwB,qBAc1B;yBArBe,mBAAmB"}
1
+ {"version":3,"file":"CommandPaletteEmpty.d.ts","sourceRoot":"","sources":["../../src/CommandPalette/CommandPaletteEmpty.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,EAAC,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAS5C,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAkB5C,MAAM,WAAW,wBAAyB,SAAQ,SAAS,CAAC,cAAc,CAAC;IACzE,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAChC,yCAAyC;IACzC,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,GAAG,EACH,QAAQ,EACR,MAAM,EACN,SAAS,EACT,KAAK,EACL,GAAG,KAAK,EACT,EAAE,wBAAwB,qBAc1B;yBArBe,mBAAmB"}
@@ -41,13 +41,14 @@ const styles = {
41
41
  * - `emptyBootstrapText`: no search term and bootstrap() returns nothing
42
42
  * - `emptySearchText`: a search query returned no results
43
43
  *
44
- * Can also be composed manually inside a custom render function.
44
+ * Can also be composed as a standalone empty result surface. Render actionable
45
+ * empty content outside listbox and option semantics.
45
46
  *
46
47
  * @example
47
48
  * ```
48
49
  * <CommandPalette
49
- * emptyBootstrapText={<CommandPaletteEmpty>Start typing to search</CommandPaletteEmpty>}
50
- * emptySearchText={<CommandPaletteEmpty>No results found</CommandPaletteEmpty>}
50
+ * emptyBootstrapText="Start typing to search"
51
+ * emptySearchText="No results found"
51
52
  * searchSource={source}
52
53
  * />
53
54
  * ```
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * SYNC: When modified, update these files to stay in sync:
8
8
  * - /apps/storybook/stories/CommandPalette.stories.tsx
9
+ * - /apps/storybook/stories/CommandPaletteInput.stories.tsx
9
10
  * - /packages/cli/assets/templates/blocks/components/CommandPalette/ (showcase blocks)
10
11
  */
11
12
  import { type ReactNode } from 'react';
@@ -25,13 +26,13 @@ export interface CommandPaletteInputProps extends Omit<BaseProps<HTMLInputElemen
25
26
  onValueChange?: (value: string) => void;
26
27
  /**
27
28
  * Placeholder text for the input.
28
- * @default 'Search...'
29
+ * @default 'Search…'
29
30
  */
30
31
  placeholder?: string;
31
32
  /**
32
- * Accessible label for the combobox input, announced by screen readers.
33
- * Falls back to the placeholder text (`'Search…'` by default), since a
34
- * placeholder alone is not a reliable accessible name.
33
+ * Accessible label for the query field, announced by screen readers. The
34
+ * placeholder is never the field's name.
35
+ * @default 'Search commands'
35
36
  */
36
37
  label?: string;
37
38
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"CommandPaletteInput.d.ts","sourceRoot":"","sources":["../../src/CommandPalette/CommandPaletteInput.tsx"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AAEH,OAAO,EAAiC,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAarE,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAkE5C,MAAM,WAAW,wBAAyB,SAAQ,IAAI,CACpD,SAAS,CAAC,gBAAgB,CAAC,EAC3B,UAAU,CACX;IACC,iEAAiE;IACjE,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAElC;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAExC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;;;OAIG;IACH,UAAU,CAAC,EAAE,SAAS,CAAC;IAEvB,qDAAqD;IACrD,QAAQ,CAAC,EAAE,KAAK,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;CACvD;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,KAAK,EAAE,eAAe,EACtB,aAAa,EACb,WAAW,EAAE,oBAAoB,EACjC,KAAK,EACL,YAAmB,EACnB,UAAU,EACV,QAAQ,EACR,SAAS,EACT,GAAG,EACH,MAAM,EACN,SAAS,EACT,KAAK,EACL,GAAG,KAAK,EACT,EAAE,wBAAwB,+BAuF1B;yBArGe,mBAAmB"}
1
+ {"version":3,"file":"CommandPaletteInput.d.ts","sourceRoot":"","sources":["../../src/CommandPalette/CommandPaletteInput.tsx"],"names":[],"mappings":"AAGA;;;;;;;;;;GAUG;AAEH,OAAO,EAAiC,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAarE,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAkE5C,MAAM,WAAW,wBAAyB,SAAQ,IAAI,CACpD,SAAS,CAAC,gBAAgB,CAAC,EAC3B,UAAU,CACX;IACC,iEAAiE;IACjE,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAElC;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAExC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;;;OAIG;IACH,UAAU,CAAC,EAAE,SAAS,CAAC;IAEvB,qDAAqD;IACrD,QAAQ,CAAC,EAAE,KAAK,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;CACvD;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,KAAK,EAAE,eAAe,EACtB,aAAa,EACb,WAAW,EAAE,oBAAoB,EACjC,KAAK,EACL,YAAmB,EACnB,UAAU,EACV,QAAQ,EACR,SAAS,EACT,GAAG,EACH,MAAM,EACN,SAAS,EACT,KAAK,EACL,GAAG,KAAK,EACT,EAAE,wBAAwB,+BA2I1B;yBAzJe,mBAAmB"}
@@ -10,13 +10,14 @@
10
10
  *
11
11
  * SYNC: When modified, update these files to stay in sync:
12
12
  * - /apps/storybook/stories/CommandPalette.stories.tsx
13
+ * - /apps/storybook/stories/CommandPaletteInput.stories.tsx
13
14
  * - /packages/cli/assets/templates/blocks/components/CommandPalette/ (showcase blocks)
14
15
  */
15
16
  import { useCallback, useEffect, useRef } from 'react';
16
17
  import * as stylex from '@stylexjs/stylex';
17
18
  import { Icon } from "../Icon/index.js";
18
19
  import { Spinner } from "../Spinner/index.js";
19
- import { mergeProps } from "../utils/index.js";
20
+ import { isImeKeyEvent, isRenderable, mergeProps } from "../utils/index.js";
20
21
  import "../theme/tokens.stylex.js";
21
22
  import { colorVars, typeScaleVars, spacingVars, typographyVars } from "../theme/tokens.stylex.js";
22
23
  import { useCommandPaletteContext } from "./CommandPaletteContext.js";
@@ -73,12 +74,26 @@ export function CommandPaletteInput({
73
74
  const t = useTranslator();
74
75
  const placeholder = placeholderFromProps ?? t('@astryx.commandPalette.input.placeholder');
75
76
  const ctx = useCommandPaletteContext();
77
+ // Inside CommandPalette the results surface is a listbox only while it holds
78
+ // selectable results; empty and pending states expose no popup.
79
+ const hasListbox = ctx ? ctx.selectableItems.length > 0 : true;
76
80
  const dialogContext = useDialogContext();
77
81
  const inputRef = useRef(null);
78
82
 
79
83
  // Use context values as fallback
80
84
  const value = controlledValue ?? ctx?.search;
81
85
  const handleValueChange = onValueChange ?? ctx?.setSearch;
86
+ const accessibleLabel = props['aria-label'] ?? label ?? t('@astryx.commandPalette.input.label');
87
+ const hasEndContent = isRenderable(endContent);
88
+ // A popup attribute the caller passes is caller-owned even while its value
89
+ // is undefined (`aria-expanded={open || undefined}`), so the role stays
90
+ // stable as the caller's popup opens and closes, and a present value is
91
+ // passed through unchanged.
92
+ // `aria-haspopup` counts unless it says there is no popup.
93
+ const callerSets = key => Object.hasOwn(props, key);
94
+ const callerDeclaresPopup = callerSets('aria-haspopup') && props['aria-haspopup'] !== false && props['aria-haspopup'] !== 'false';
95
+ const callerOwnsPopup = !ctx && (props.role === 'combobox' || callerSets('aria-expanded') || callerSets('aria-autocomplete') || callerSets('aria-controls') || callerSets('aria-owns') || callerSets('aria-activedescendant') || callerDeclaresPopup);
96
+ const standaloneRole = callerSets('role') ? props.role : callerOwnsPopup ? 'combobox' : 'searchbox';
82
97
 
83
98
  // When rendered inside an inline dialog, disable auto-focus by default
84
99
  // to avoid stealing focus from the surrounding page.
@@ -96,7 +111,10 @@ export function CommandPaletteInput({
96
111
  // Keyboard navigation — delegates to useCombobox via context
97
112
  const handleKeyDown = useCallback(e => {
98
113
  onKeyDown?.(e);
99
- if (e.defaultPrevented) {
114
+ if (e.defaultPrevented || isImeKeyEvent(e.nativeEvent)) {
115
+ // An in-progress IME composition owns Enter, Escape, and arrows. Let
116
+ // the input method finish or cancel composition without selecting or
117
+ // dismissing palette content.
100
118
  return;
101
119
  }
102
120
  // Delegate to useCombobox's keyboard handler from context
@@ -114,17 +132,20 @@ export function CommandPaletteInput({
114
132
  color: "inherit"
115
133
  })
116
134
  }), /*#__PURE__*/_jsx("input", {
135
+ ...props,
117
136
  ref: useMergedRefs(ref, inputRef),
137
+ ...{
138
+ className: "x98rzlu xeuugli xc342km xng3xce x1a2a7pz xjbqb8w x1tgivj0 x9ynric xjm74w1 xf9zqsd xw6l6zx x1717udv xeyghm5"
139
+ },
118
140
  type: "text",
119
- role: "combobox",
120
- "aria-expanded": ctx?.isOpen ?? true,
121
- "aria-autocomplete": "list",
122
- "aria-controls": ctx?.listId,
123
- "aria-activedescendant": ctx && ctx.highlightedIndex >= 0 ? ctx.getItemId(ctx.highlightedIndex) : undefined
124
- // A placeholder alone is not a reliable accessible name; give the
125
- // combobox an explicit one (consumer aria-label via rest props wins).
141
+ role: ctx ? 'combobox' : standaloneRole,
142
+ "aria-expanded": ctx ? ctx.isOpen && hasListbox : callerSets('aria-expanded') ? props['aria-expanded'] : callerOwnsPopup || undefined,
143
+ "aria-autocomplete": ctx ? 'list' : callerSets('aria-autocomplete') ? props['aria-autocomplete'] : callerOwnsPopup ? 'list' : undefined,
144
+ "aria-controls": ctx ? hasListbox ? ctx.listId : undefined : props['aria-controls'],
145
+ "aria-activedescendant": ctx ? hasListbox && ctx.highlightedIndex >= 0 && ctx.highlightedIndex < ctx.selectableItems.length ? ctx.getItemId(ctx.highlightedIndex) : undefined : props['aria-activedescendant']
146
+ // Placeholder text is never the field's name (AST-056 AR2).
126
147
  ,
127
- "aria-label": label ?? placeholder,
148
+ "aria-label": accessibleLabel,
128
149
  placeholder: placeholder,
129
150
  value: value,
130
151
  "data-autofocus": effectiveAutoFocus || undefined,
@@ -132,12 +153,8 @@ export function CommandPaletteInput({
132
153
  handleValueChange?.(e.target.value);
133
154
  onChange?.(e);
134
155
  },
135
- onKeyDown: handleKeyDown,
136
- ...{
137
- className: "x98rzlu xeuugli xc342km xng3xce x1a2a7pz xjbqb8w x1tgivj0 x9ynric xjm74w1 xf9zqsd xw6l6zx x1717udv xeyghm5"
138
- },
139
- ...props
140
- }), (ctx?.isBusy || endContent) && /*#__PURE__*/_jsxs("span", {
156
+ onKeyDown: handleKeyDown
157
+ }), (ctx?.isBusy || hasEndContent) && /*#__PURE__*/_jsxs("span", {
141
158
  ...{
142
159
  className: "x78zum5 x6s0dn4 xzye2dw x2lah0s"
143
160
  },
@@ -148,8 +165,8 @@ export function CommandPaletteInput({
148
165
  children: /*#__PURE__*/_jsx(Spinner, {
149
166
  size: "sm"
150
167
  })
151
- }), endContent]
152
- }), ' ']
168
+ }), hasEndContent && endContent]
169
+ })]
153
170
  });
154
171
  }
155
172
  CommandPaletteInput.displayName = 'CommandPaletteInput';
@@ -16,8 +16,10 @@ export interface CommandPaletteListProps extends BaseProps<HTMLDivElement> {
16
16
  label?: string;
17
17
  }
18
18
  /**
19
- * Scrollable results container for the command palette.
20
- * Renders as a listbox for ARIA compliance.
19
+ * Scrollable results container for the command palette. Standalone composition
20
+ * renders as a listbox. Inside CommandPalette, listbox semantics are present
21
+ * only while selectable results exist; empty and pending states retain the same
22
+ * styled container without exposing an empty interactive popup.
21
23
  *
22
24
  * When used inside CommandPalette, automatically gets the correct
23
25
  * ID for aria-controls linking with the input.
@@ -1 +1 @@
1
- {"version":3,"file":"CommandPaletteList.d.ts","sourceRoot":"","sources":["../../src/CommandPalette/CommandPaletteList.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAErC,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAmB5C,MAAM,WAAW,uBAAwB,SAAQ,SAAS,CAAC,cAAc,CAAC;IACxE;;OAEG;IACH,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAEhC;;OAEG;IACH,QAAQ,EAAE,SAAS,CAAC;IAEpB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,QAAQ,EACR,KAAK,EAAE,cAAc,EACrB,GAAG,EACH,MAAM,EACN,SAAS,EACT,KAAK,EACL,GAAG,KAAK,EACT,EAAE,uBAAuB,+BAqBzB;yBA7Be,kBAAkB"}
1
+ {"version":3,"file":"CommandPaletteList.d.ts","sourceRoot":"","sources":["../../src/CommandPalette/CommandPaletteList.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAErC,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAmB5C,MAAM,WAAW,uBAAwB,SAAQ,SAAS,CAAC,cAAc,CAAC;IACxE;;OAEG;IACH,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAEhC;;OAEG;IACH,QAAQ,EAAE,SAAS,CAAC;IAEpB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,QAAQ,EACR,KAAK,EAAE,cAAc,EACrB,GAAG,EACH,MAAM,EACN,SAAS,EACT,KAAK,EACL,GAAG,KAAK,EACT,EAAE,uBAAuB,+BAwBzB;yBAhCe,kBAAkB"}
@@ -34,8 +34,10 @@ const styles = {
34
34
  }
35
35
  };
36
36
  /**
37
- * Scrollable results container for the command palette.
38
- * Renders as a listbox for ARIA compliance.
37
+ * Scrollable results container for the command palette. Standalone composition
38
+ * renders as a listbox. Inside CommandPalette, listbox semantics are present
39
+ * only while selectable results exist; empty and pending states retain the same
40
+ * styled container without exposing an empty interactive popup.
39
41
  *
40
42
  * When used inside CommandPalette, automatically gets the correct
41
43
  * ID for aria-controls linking with the input.
@@ -65,12 +67,15 @@ export function CommandPaletteList({
65
67
  const t = useTranslator();
66
68
  const label = labelFromProps ?? t('@astryx.commandPalette.list.label');
67
69
  const ctx = useCommandPaletteContext();
70
+ // Inside CommandPalette the list is a listbox only while it holds selectable
71
+ // results; standalone composition is always a listbox.
72
+ const hasListbox = ctx ? ctx.selectableItems.length > 0 : true;
68
73
  return /*#__PURE__*/_jsx("div", {
69
74
  ref: ref,
70
75
  ...props,
71
76
  id: ctx?.listId ?? props.id,
72
- role: "listbox",
73
- "aria-label": label,
77
+ role: hasListbox ? 'listbox' : undefined,
78
+ "aria-label": hasListbox ? label : undefined,
74
79
  ...mergeProps(themeProps('command-palette-list'), stylex.props(styles.list, xstyle), className, style),
75
80
  children: children
76
81
  });
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @file ContextMenu.tsx
3
- * @input Uses React, StyleX, useLayer, BottomSheet, useListFocus, and the
4
- * shared menu-presentation resolver
3
+ * @input Uses React, StyleX, useLayer, shared layer dismissal, BottomSheet,
4
+ * useListFocus, and the shared menu-presentation resolver
5
5
  * @output Exports ContextMenu with cursor-popover and touch-sheet presentations
6
6
  * @position Core implementation; consumed by index.ts
7
7
  *
@@ -117,7 +117,7 @@ export type ContextMenuProps = ContextMenuDataProps | ContextMenuCompoundProps;
117
117
  * </ContextMenu>
118
118
  * ```
119
119
  */
120
- export declare function ContextMenu({ children, menuWidth, size, label: labelFromProps, isDisabled, onOpenChange, presentation, triggerAs, ref, className, style, xstyle, triggerXstyle, 'data-testid': testId, ...rest }: ContextMenuProps): React.JSX.Element;
120
+ export declare function ContextMenu({ children, menuWidth, size, label: labelFromProps, isDisabled, onOpenChange, presentation, triggerAs, ref, className, style, xstyle, triggerXstyle, onContextMenu: onContextMenuProp, onTouchStart: onTouchStartProp, onTouchMove: onTouchMoveProp, onTouchEnd: onTouchEndProp, onTouchCancel: onTouchCancelProp, 'data-testid': testId, ...rest }: ContextMenuProps): React.JSX.Element;
121
121
  export declare namespace ContextMenu {
122
122
  var displayName: string;
123
123
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ContextMenu.d.ts","sourceRoot":"","sources":["../../src/ContextMenu/ContextMenu.tsx"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,KASN,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAC,SAAS,EAAC,M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EACrB,UAAkB,EAClB,YAAY,EACZ,YAAwB,EACxB,SAAiB,EACjB,GAAG,EACH,SAAS,EACT,KAAK,EACL,MAAM,EACN,aAAa,EACb,aAAa,EAAE,iBAAiB,EAChC,YAAY,EAAE,gBAAgB,EAC9B,WAAW,EAAE,eAAe,EAC5B,UAAU,EAAE,cAAc,EAC1B,aAAa,EAAE,iBAAiB,EAChC,aAAa,EAAE,MAAM,EACrB,GAAG,IAAI,EACR,EAAE,gBAAgB,qBAoelB;yBAzfe,WAAW"}
@@ -3,8 +3,8 @@
3
3
 
4
4
  /**
5
5
  * @file ContextMenu.tsx
6
- * @input Uses React, StyleX, useLayer, BottomSheet, useListFocus, and the
7
- * shared menu-presentation resolver
6
+ * @input Uses React, StyleX, useLayer, shared layer dismissal, BottomSheet,
7
+ * useListFocus, and the shared menu-presentation resolver
8
8
  * @output Exports ContextMenu with cursor-popover and touch-sheet presentations
9
9
  * @position Core implementation; consumed by index.ts
10
10
  *
@@ -39,6 +39,8 @@ import { Button } from "../Button/index.js";
39
39
  import { Heading } from "../Heading/index.js";
40
40
  import { Icon } from "../Icon/index.js";
41
41
  import { useLayer } from "../Layer/useLayer.js";
42
+ import { LayerDepthProvider } from "../Layer/LayerDepthContext.js";
43
+ import { useLayerDismissal } from "../Layer/useLayerDismissal.js";
42
44
  import { MenuBottomSheetActionList } from "../DropdownMenu/MenuBottomSheetActionList.js";
43
45
  import { renderDropdownItems } from "../DropdownMenu/renderDropdownItems.js";
44
46
  import { DropdownMenuContext } from "../DropdownMenu/DropdownMenuContext.js";
@@ -52,7 +54,7 @@ import { useLongPress } from "../hooks/useLongPress.js";
52
54
  import { layerAnimations } from "../Layer/layerAnimations.stylex.js";
53
55
  import "../theme/tokens.stylex.js";
54
56
  import { colorVars, spacingVars, radiusVars, durationVars, easeVars, shadowVars } from "../theme/tokens.stylex.js";
55
- import { mergeProps, isImeKeyEvent, rtlStyles } from "../utils/index.js";
57
+ import { mergeProps, rtlStyles } from "../utils/index.js";
56
58
  import { themeProps } from "../utils/themeProps.js";
57
59
  import { useTranslator } from "../i18n/index.js";
58
60
  import { useMergedRefs } from "../hooks/useMergedRefs.js";
@@ -194,6 +196,11 @@ export function ContextMenu({
194
196
  style,
195
197
  xstyle,
196
198
  triggerXstyle,
199
+ onContextMenu: onContextMenuProp,
200
+ onTouchStart: onTouchStartProp,
201
+ onTouchMove: onTouchMoveProp,
202
+ onTouchEnd: onTouchEndProp,
203
+ onTouchCancel: onTouchCancelProp,
197
204
  'data-testid': testId,
198
205
  ...rest
199
206
  }) {
@@ -226,7 +233,6 @@ export function ContextMenu({
226
233
  // Element focused before the menu opened, restored when it closes so focus
227
234
  // does not fall to <body> after Escape or outside-click dismissal.
228
235
  const triggerFocusRef = useRef(null);
229
- const sheetHeadingRef = useRef(null);
230
236
  const [isOpen, setIsOpen] = useState(false);
231
237
  const [submenuPath, setSubmenuPath] = useState([]);
232
238
  const currentSubmenu = submenuPath.at(-1);
@@ -274,16 +280,12 @@ export function ContextMenu({
274
280
  closeMenu();
275
281
  }
276
282
  }, [closeMenu]);
277
- useEffect(() => {
278
- if (!isOpen || submenuPath.length === 0) {
279
- return;
280
- }
281
- const frame = requestAnimationFrame(() => {
282
- sheetHeadingRef.current?.focus({
283
+ const setSheetHeadingRef = useCallback(node => {
284
+ if (node && isOpen && submenuPath.length > 0) {
285
+ node.focus({
283
286
  preventScroll: true
284
287
  });
285
- });
286
- return () => cancelAnimationFrame(frame);
288
+ }
287
289
  }, [isOpen, submenuPath.length]);
288
290
  const {
289
291
  listRef,
@@ -297,8 +299,15 @@ export function ContextMenu({
297
299
  boundarySelector: MENU_BOUNDARY_SELECTOR,
298
300
  // Menus wrap from the last row to the first and back.
299
301
  wrap: true,
300
- hasPaging: true,
301
- onEscape: closeMenu
302
+ hasPaging: true
303
+ });
304
+
305
+ // Join the shared stack so an Escape press dismisses exactly one top-most
306
+ // surface. BottomSheet owns its own dismissal path.
307
+ useLayerDismissal({
308
+ isActive: isOpen && !usesBottomSheet,
309
+ onDismiss: closeMenu,
310
+ getContainer: () => listRef.current
302
311
  });
303
312
 
304
313
  // Typeahead over the enabled menu items, matched on each row's LABEL alone.
@@ -329,32 +338,6 @@ export function ContextMenu({
329
338
  document.removeEventListener('mousedown', handleClickOutside);
330
339
  };
331
340
  }, [isOpen, closeMenu, listRef, usesBottomSheet]);
332
-
333
- // Dismiss on Escape from anywhere while open. The menu div's own onKeyDown
334
- // only fires when focus is inside the menu; a document-level listener is
335
- // kept as a reliable fallback Escape path (e.g. if focus has moved out of
336
- // the menu). Guards against IME composition-cancel.
337
- useEffect(() => {
338
- if (!isOpen || usesBottomSheet) {
339
- return;
340
- }
341
- const handleEscape = e => {
342
- if (e.key !== 'Escape') {
343
- return;
344
- }
345
- if (isImeKeyEvent(e)) {
346
- // Ignore Escape that is committing/cancelling an IME composition;
347
- // see utils/ime.ts for why.
348
- return;
349
- }
350
- e.preventDefault();
351
- closeMenu();
352
- };
353
- document.addEventListener('keydown', handleEscape);
354
- return () => {
355
- document.removeEventListener('keydown', handleEscape);
356
- };
357
- }, [isOpen, closeMenu, usesBottomSheet]);
358
341
  const listKeyDown = useCallback(e => {
359
342
  // A submenu flyout renders inline inside this menu; its key events bubble
360
343
  // up here. Let that level own them — only handle events from this level.
@@ -447,13 +430,42 @@ export function ContextMenu({
447
430
  // held long enough (see useLongPress for timer/move-cancel/cleanup logic).
448
431
  // The hook also returns the imperative start/moveTo/cancel API the menu press
449
432
  // model drives; only its four touch handlers belong on the trigger element.
450
- const longPress = useLongPress({
433
+ const {
434
+ onTouchStart: handleLongPressTouchStart,
435
+ onTouchMove: handleLongPressTouchMove,
436
+ onTouchEnd: handleLongPressTouchEnd,
437
+ onTouchCancel: handleLongPressTouchCancel
438
+ } = useLongPress({
451
439
  disabled: isDisabled,
452
440
  onLongPress: useCallback(point => {
453
441
  const rect = getAnchorBaseRect();
454
442
  openAtLocalPoint(rect ? point.x - rect.left : point.x, rect ? point.y - rect.top : point.y, triggerRef.current);
455
443
  }, [openAtLocalPoint, getAnchorBaseRect])
456
444
  });
445
+
446
+ // ContextMenu owns invocation and long-press cleanup. Consumer handlers are
447
+ // notified too, but preventing their default does not cancel component-owned
448
+ // behavior that the public API does not promise as cancelable.
449
+ const handleTriggerContextMenu = useCallback(event => {
450
+ handleContextMenu(event);
451
+ onContextMenuProp?.(event);
452
+ }, [handleContextMenu, onContextMenuProp]);
453
+ const handleTriggerTouchStart = useCallback(event => {
454
+ handleLongPressTouchStart(event);
455
+ onTouchStartProp?.(event);
456
+ }, [handleLongPressTouchStart, onTouchStartProp]);
457
+ const handleTriggerTouchMove = useCallback(event => {
458
+ handleLongPressTouchMove(event);
459
+ onTouchMoveProp?.(event);
460
+ }, [handleLongPressTouchMove, onTouchMoveProp]);
461
+ const handleTriggerTouchEnd = useCallback(event => {
462
+ handleLongPressTouchEnd();
463
+ onTouchEndProp?.(event);
464
+ }, [handleLongPressTouchEnd, onTouchEndProp]);
465
+ const handleTriggerTouchCancel = useCallback(event => {
466
+ handleLongPressTouchCancel();
467
+ onTouchCancelProp?.(event);
468
+ }, [handleLongPressTouchCancel, onTouchCancelProp]);
457
469
  const popoverXstyle = menuWidth ? styles.popoverCustomWidth(menuWidth) : styles.popover;
458
470
 
459
471
  // The drill-in view stack for sub-menus on a phone; the bottom sheet has
@@ -517,7 +529,7 @@ export function ContextMenu({
517
529
  isIconOnly: true,
518
530
  onClick: () => setSubmenuPath(path => path.slice(0, -1))
519
531
  }), /*#__PURE__*/_jsx(Heading, {
520
- ref: sheetHeadingRef,
532
+ ref: setSheetHeadingRef,
521
533
  level: 3,
522
534
  tabIndex: -1,
523
535
  xstyle: [styles.sheetViewHeading, submenuPath.length === 0 && styles.sheetRootHeading],
@@ -537,11 +549,11 @@ export function ContextMenu({
537
549
  children: [/*#__PURE__*/_jsxs(TriggerElement, {
538
550
  ref: useMergedRefs(ref, triggerRef),
539
551
  ...triggerProps,
540
- onContextMenu: handleContextMenu,
541
- onTouchStart: longPress.onTouchStart,
542
- onTouchMove: longPress.onTouchMove,
543
- onTouchEnd: longPress.onTouchEnd,
544
- onTouchCancel: longPress.onTouchCancel,
552
+ onContextMenu: handleTriggerContextMenu,
553
+ onTouchStart: handleTriggerTouchStart,
554
+ onTouchMove: handleTriggerTouchMove,
555
+ onTouchEnd: handleTriggerTouchEnd,
556
+ onTouchCancel: handleTriggerTouchCancel,
545
557
  "data-testid": testId,
546
558
  ...stylex.props(styles.trigger, ...(triggerXstyle ? Array.isArray(triggerXstyle) ? triggerXstyle : [triggerXstyle] : [])),
547
559
  children: [children, /*#__PURE__*/_jsx("span", {
@@ -564,7 +576,9 @@ export function ContextMenu({
564
576
  label: sheetLabel,
565
577
  children: renderedBottomSheetContent
566
578
  })
567
- }) : layer.render(renderedMenu, {
579
+ }) : layer.render(/*#__PURE__*/_jsx(LayerDepthProvider, {
580
+ children: renderedMenu
581
+ }), {
568
582
  placement: 'below',
569
583
  alignment: 'start',
570
584
  xstyle: [popoverXstyle, layerAnimations.below]