@astryxdesign/core 0.7.7-canary.1d04d40 → 0.7.7-canary.1f47db9

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 (78) hide show
  1. package/dist/DateInput/Wheel.d.ts +17 -1
  2. package/dist/DateInput/Wheel.d.ts.map +1 -1
  3. package/dist/DateInput/Wheel.js +179 -19
  4. package/dist/Drawer/useDrawerDialogPresence.d.ts.map +1 -1
  5. package/dist/Drawer/useDrawerDialogPresence.js +4 -0
  6. package/dist/DropdownMenu/DropdownMenu.d.ts.map +1 -1
  7. package/dist/DropdownMenu/DropdownMenu.js +20 -4
  8. package/dist/Layer/usePressPin.d.ts.map +1 -1
  9. package/dist/Layer/usePressPin.js +42 -12
  10. package/dist/Layer/useTouchTrigger.d.ts.map +1 -1
  11. package/dist/Layer/useTouchTrigger.js +16 -5
  12. package/dist/ProgressBar/ProgressBar.d.ts +1 -1
  13. package/dist/ProgressBar/ProgressBar.d.ts.map +1 -1
  14. package/dist/ProgressBar/ProgressBar.js +33 -6
  15. package/dist/Switch/Switch.d.ts +1 -1
  16. package/dist/Switch/Switch.d.ts.map +1 -1
  17. package/dist/Switch/Switch.js +200 -46
  18. package/dist/Switch/switchFill.d.ts +31 -0
  19. package/dist/Switch/switchFill.d.ts.map +1 -0
  20. package/dist/Switch/switchFill.js +88 -0
  21. package/dist/Switch/switchTouch.d.ts +81 -0
  22. package/dist/Switch/switchTouch.d.ts.map +1 -0
  23. package/dist/Switch/switchTouch.js +133 -0
  24. package/dist/Switch/useSwitchTouch.d.ts +285 -0
  25. package/dist/Switch/useSwitchTouch.d.ts.map +1 -0
  26. package/dist/Switch/useSwitchTouch.js +997 -0
  27. package/dist/astryx.css +46 -2
  28. package/dist/gestures/GestureHost.d.ts.map +1 -1
  29. package/dist/gestures/GestureHost.js +4 -3
  30. package/dist/gestures/PressTracker.d.ts +6 -0
  31. package/dist/gestures/PressTracker.d.ts.map +1 -1
  32. package/dist/gestures/PressTracker.js +3 -0
  33. package/dist/gestures/types.d.ts +6 -0
  34. package/dist/gestures/types.d.ts.map +1 -1
  35. package/dist/gestures/usePressTracker.d.ts.map +1 -1
  36. package/dist/gestures/usePressTracker.js +1 -0
  37. package/dist/motion/uikit/index.d.ts +6 -4
  38. package/dist/motion/uikit/index.d.ts.map +1 -1
  39. package/dist/motion/uikit/index.js +6 -4
  40. package/dist/motion/uikit/progressBar.d.ts +27 -7
  41. package/dist/motion/uikit/progressBar.d.ts.map +1 -1
  42. package/dist/motion/uikit/progressBar.js +31 -11
  43. package/dist/motion/uikit/springs.d.ts +13 -29
  44. package/dist/motion/uikit/springs.d.ts.map +1 -1
  45. package/dist/motion/uikit/springs.js +16 -30
  46. package/dist/motion/uikit/switch.d.ts +166 -0
  47. package/dist/motion/uikit/switch.d.ts.map +1 -0
  48. package/dist/motion/uikit/switch.js +186 -0
  49. package/dist/privateAttributes/pressHoldsDrag.stylex.d.ts +18 -0
  50. package/dist/privateAttributes/pressHoldsDrag.stylex.d.ts.map +1 -0
  51. package/dist/privateAttributes/pressHoldsDrag.stylex.js +28 -0
  52. package/dist/utils/pressFeedback.d.ts.map +1 -1
  53. package/dist/utils/pressFeedback.js +5 -0
  54. package/package.json +4 -4
  55. package/src/DateInput/Wheel.tsx +174 -14
  56. package/src/Drawer/useDrawerDialogPresence.ts +4 -0
  57. package/src/DropdownMenu/DropdownMenu.tsx +28 -6
  58. package/src/Layer/usePressPin.ts +48 -13
  59. package/src/Layer/useTouchTrigger.ts +19 -5
  60. package/src/ProgressBar/ProgressBar.doc.mjs +4 -2
  61. package/src/ProgressBar/ProgressBar.tsx +67 -7
  62. package/src/Switch/Switch.doc.mjs +3 -3
  63. package/src/Switch/Switch.tsx +412 -86
  64. package/src/Switch/switchFill.ts +106 -0
  65. package/src/Switch/switchTouch.ts +194 -0
  66. package/src/Switch/useSwitchTouch.ts +1117 -0
  67. package/src/gestures/GestureHost.ts +7 -3
  68. package/src/gestures/PressTracker.ts +10 -0
  69. package/src/gestures/types.ts +6 -0
  70. package/src/gestures/usePressTracker.ts +2 -0
  71. package/src/motion/MEASUREMENTS.md +29 -27
  72. package/src/motion/README.md +2 -1
  73. package/src/motion/uikit/index.ts +5 -4
  74. package/src/motion/uikit/progressBar.ts +31 -11
  75. package/src/motion/uikit/springs.ts +16 -30
  76. package/src/motion/uikit/switch.ts +174 -0
  77. package/src/privateAttributes/pressHoldsDrag.stylex.ts +28 -0
  78. package/src/utils/pressFeedback.ts +5 -0
@@ -3,7 +3,10 @@ export interface WheelOption {
3
3
  value: number;
4
4
  /** Row text. */
5
5
  label: string;
6
- /** Rows outside min/max stay visible but cannot be committed. */
6
+ /**
7
+ * Rows outside min/max stay visible but cannot be committed: a wheel that
8
+ * stops on one travels on to the nearest enabled row.
9
+ */
7
10
  isDisabled?: boolean;
8
11
  }
9
12
  export interface WheelProps {
@@ -21,6 +24,19 @@ export interface WheelProps {
21
24
  */
22
25
  isActive?: boolean;
23
26
  }
27
+ /**
28
+ * The enabled row nearest `index`: `index` itself when it is enabled,
29
+ * otherwise the closest enabled row on either side. A tie goes to the side of
30
+ * `towardIndex` (the committed row), and a wheel with no enabled row stays on
31
+ * `towardIndex`.
32
+ *
33
+ * @example
34
+ * ```
35
+ * // Hours 0-23 with 09:00-17:00 bounds: stopping on 7 rests on 9.
36
+ * nearestEnabledIndex(hourOptions, 7, 10); // 9
37
+ * ```
38
+ */
39
+ export declare function nearestEnabledIndex(options: ReadonlyArray<WheelOption>, index: number, towardIndex: number): number;
24
40
  /**
25
41
  * One snap-scrolling picker column.
26
42
  *
@@ -1 +1 @@
1
- {"version":3,"file":"Wheel.d.ts","sourceRoot":"","sources":["../../src/DateInput/Wheel.tsx"],"names":[],"mappings":"AA8MA,MAAM,WAAW,WAAW;IAC1B,oEAAoE;IACpE,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,iEAAiE;IACjE,UAAU,CAAC,EAAE,OAA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,KAAK,EACL,OAAO,EACP,KAAK,EACL,QAAQ,EACR,QAAe,GAChB,EAAE,UAAU,+BAkVZ;yBAxVe,KAAK"}
@@ -21,6 +21,11 @@
21
21
  * browser that does not understand `animation-timeline` would otherwise run
22
22
  * the same keyframes on the document timeline and simply play them once.
23
23
  *
24
+ * Under Reduce Motion, the wheel's own scrolls (a step from a key or a click,
25
+ * the travel to the nearest enabled row) land without travel. They cross-fade
26
+ * on a touch screen and land at once otherwise. A finger's scroll and its
27
+ * momentum stay the platform's.
28
+ *
24
29
  * Accessibility: this is a listbox, not a novel widget. It is one tab stop
25
30
  * with arrow/Home/End/PageUp/PageDown keys, `aria-activedescendant` tracking
26
31
  * the active row, and every row reachable by tap — none of which depends on
@@ -37,6 +42,7 @@ import * as stylex from '@stylexjs/stylex';
37
42
  import "../theme/tokens.stylex.js";
38
43
  import { colorVars, radiusVars, fontWeightVars, typeScaleVars, spacingVars, durationVars } from "../theme/tokens.stylex.js";
39
44
  import { focusOutlineStyles } from "../utils/index.js";
45
+ import { reducedMotionFade } from "../motion/reducedMotion.js";
40
46
  import "./tokens.stylex.js";
41
47
  import { dateInputTouchSizes, dateInputTouchGeometry } from "./tokens.stylex.js";
42
48
  import { useOwnScrollGesture } from "./useOwnScrollGesture.js";
@@ -72,6 +78,41 @@ const styles = {
72
78
  $$css: true
73
79
  }
74
80
  };
81
+ /**
82
+ * The enabled row nearest `index`: `index` itself when it is enabled,
83
+ * otherwise the closest enabled row on either side. A tie goes to the side of
84
+ * `towardIndex` (the committed row), and a wheel with no enabled row stays on
85
+ * `towardIndex`.
86
+ *
87
+ * @example
88
+ * ```
89
+ * // Hours 0-23 with 09:00-17:00 bounds: stopping on 7 rests on 9.
90
+ * nearestEnabledIndex(hourOptions, 7, 10); // 9
91
+ * ```
92
+ */
93
+ export function nearestEnabledIndex(options, index, towardIndex) {
94
+ const isEnabled = i => i >= 0 && i < options.length && !options[i].isDisabled;
95
+ if (isEnabled(index)) {
96
+ return index;
97
+ }
98
+ for (let distance = 1; distance < options.length; distance++) {
99
+ const below = index - distance;
100
+ const above = index + distance;
101
+ const isBelowEnabled = isEnabled(below);
102
+ const isAboveEnabled = isEnabled(above);
103
+ if (isBelowEnabled && isAboveEnabled) {
104
+ return towardIndex < index ? below : above;
105
+ }
106
+ if (isBelowEnabled) {
107
+ return below;
108
+ }
109
+ if (isAboveEnabled) {
110
+ return above;
111
+ }
112
+ }
113
+ return towardIndex;
114
+ }
115
+
75
116
  /**
76
117
  * One snap-scrolling picker column.
77
118
  *
@@ -114,20 +155,110 @@ export function Wheel({
114
155
  const first = scrollerRef.current?.firstElementChild;
115
156
  return first instanceof HTMLElement && first.offsetHeight > 0 ? first.offsetHeight : 0;
116
157
  }, []);
117
- const scrollToIndex = useCallback((index, behavior) => {
158
+
159
+ // What last started a scroll of the wheel: a pointer's type, or 'wheel'
160
+ // for a mouse wheel or trackpad. Under Reduce Motion the release of a touch
161
+ // drag cross-fades on any primary pointer. A key step, a row tap or a
162
+ // trackpad's scroll cross-fades on a coarse primary pointer and lands at
163
+ // once on a fine one.
164
+ const lastPointerRef = useRef(null);
165
+
166
+ // A reduced-motion dip whose rows have not landed yet: its timer and the
167
+ // row it lands on. While one is pending the rows stay put for it, so they
168
+ // never move at full opacity, and a further step retargets it.
169
+ const pendingFadeRef = useRef(null);
170
+ // The running dip, so a step during its fade-in starts the next one where
171
+ // the column is.
172
+ const dipRef = useRef(null);
173
+ useEffect(() => () => {
174
+ if (pendingFadeRef.current != null) {
175
+ window.clearTimeout(pendingFadeRef.current.timer);
176
+ pendingFadeRef.current = null;
177
+ }
178
+ }, []);
179
+ const scrollToIndex = useCallback((index, behavior, {
180
+ touchRelease = false
181
+ } = {}) => {
118
182
  const scroller = scrollerRef.current;
119
183
  const size = itemBlockSize();
120
184
  if (scroller == null || size === 0) {
121
185
  return;
122
186
  }
123
- scroller.scrollTo({
124
- top: index * size,
125
- behavior
187
+ const top = index * size;
188
+ // Under Reduce Motion the wheel's own scroll lands without travel. It
189
+ // dips on a touch screen or for a touch drag's release. Otherwise it
190
+ // lands at once.
191
+ const fadeTiming = behavior === 'smooth' ? reducedMotionFade(scroller, {
192
+ touchRelease
193
+ }) : null;
194
+ const pending = pendingFadeRef.current;
195
+ if (fadeTiming == null) {
196
+ if (pending != null) {
197
+ window.clearTimeout(pending.timer);
198
+ pendingFadeRef.current = null;
199
+ }
200
+ scroller.scrollTo({
201
+ top,
202
+ behavior
203
+ });
204
+ return;
205
+ }
206
+ if (fadeTiming.duration === 0 || typeof scroller.animate !== 'function') {
207
+ if (pending != null) {
208
+ window.clearTimeout(pending.timer);
209
+ pendingFadeRef.current = null;
210
+ }
211
+ scroller.scrollTo({
212
+ top,
213
+ behavior: 'auto'
214
+ });
215
+ return;
216
+ }
217
+ if (pending != null) {
218
+ // The dip is still fading out: its rows land here instead.
219
+ pending.top = top;
220
+ return;
221
+ }
222
+ const {
223
+ duration,
224
+ easing
225
+ } = fadeTiming;
226
+ // A step during the last dip's fade-in starts the new dip at the
227
+ // column's current opacity, not at full opacity. A leaving element fades
228
+ // out from where it is.
229
+ const shown = Number.parseFloat(getComputedStyle(scroller).opacity);
230
+ dipRef.current?.cancel();
231
+ dipRef.current = scroller.animate([{
232
+ opacity: Number.isFinite(shown) ? shown : 1,
233
+ easing
234
+ }, {
235
+ opacity: 0,
236
+ easing
237
+ }, {
238
+ opacity: 1
239
+ }], {
240
+ duration,
241
+ easing: 'linear'
126
242
  });
243
+ const landing = {
244
+ top,
245
+ timer: 0
246
+ };
247
+ landing.timer = window.setTimeout(() => {
248
+ pendingFadeRef.current = null;
249
+ scroller.scrollTo({
250
+ top: landing.top,
251
+ behavior: 'auto'
252
+ });
253
+ }, duration / 2);
254
+ pendingFadeRef.current = landing;
127
255
  }, [itemBlockSize]);
128
256
 
129
- // Commit on rest. A disabled row is bounced back to the committed one
130
- // rather than silently keeping a value the wheel is not showing.
257
+ // Commit on rest. A wheel that stops on a disabled row travels on to the
258
+ // nearest enabled row, as UIDatePicker does. That second rest commits it.
259
+ // A rest on the committed row is not a stop to correct. The park after the
260
+ // sheet opens rests there with no touch. A committed value outside the
261
+ // bounds stays until a person moves the wheel.
131
262
  //
132
263
  // Declared here, above the park effect, because that effect consults the
133
264
  // `isAtRestRef` this returns before it repositions anything.
@@ -139,18 +270,24 @@ export function Wheel({
139
270
  return;
140
271
  }
141
272
  const index = Math.min(options.length - 1, Math.max(0, Math.round(scroller.scrollTop / size)));
142
- const option = options[index];
143
- if (option == null || option.isDisabled) {
144
- scrollToIndex(selectedIndex, 'smooth');
273
+ const restIndex = index === selectedIndex ? index : nearestEnabledIndex(options, index, selectedIndex);
274
+ if (restIndex !== index) {
275
+ scrollToIndex(restIndex, 'smooth', {
276
+ touchRelease: lastPointerRef.current === 'touch'
277
+ });
145
278
  return;
146
279
  }
147
- if (option.value !== value) {
280
+ const option = options[index];
281
+ if (option != null && !option.isDisabled && option.value !== value) {
148
282
  onChange(option.value);
149
283
  }
150
284
  }, isActive, isDraggingRef);
151
285
 
152
- // Park the committed row under the band whenever the wheel is shown, or the
153
- // value is changed from outside (the calendar scrolled to another month).
286
+ // Park the committed row under the band at once whenever the wheel is
287
+ // shown. A value that changes from outside while the wheel is shown turns
288
+ // the wheel onto its row instead. UIDatePicker turns onto its maximum the
289
+ // same way, and never jumps there. For example, a bound clamps the time
290
+ // after another wheel turned, or the calendar moved to another month.
154
291
  //
155
292
  // NEVER while the wheel is still moving. A scroller that is mid-gesture or
156
293
  // still carrying momentum is the user's, and repositioning it does not stop
@@ -158,8 +295,15 @@ export function Wheel({
158
295
  // as a new settle, commits the next row along, and parks again. See
159
296
  // useScrollSettle. The settle handler re-checks the position afterwards, so
160
297
  // a correction that is genuinely needed still happens, just at rest.
298
+ const parkedRef = useRef(false);
161
299
  useEffect(() => {
162
- if (!isActive || !isAtRestRef.current) {
300
+ if (!isActive) {
301
+ parkedRef.current = false;
302
+ return;
303
+ }
304
+ // Nor while a reduced-motion dip is still to land its rows: they land
305
+ // under it, on this row.
306
+ if (!isAtRestRef.current || pendingFadeRef.current != null) {
163
307
  return;
164
308
  }
165
309
  const size = itemBlockSize();
@@ -168,14 +312,19 @@ export function Wheel({
168
312
  return;
169
313
  }
170
314
  if (Math.round(scroller.scrollTop / size) !== selectedIndex) {
171
- scroller.scrollTo({
172
- top: selectedIndex * size,
173
- behavior: 'auto'
174
- });
315
+ if (parkedRef.current) {
316
+ scrollToIndex(selectedIndex, 'smooth');
317
+ } else {
318
+ scroller.scrollTo({
319
+ top: selectedIndex * size,
320
+ behavior: 'auto'
321
+ });
322
+ }
175
323
  }
324
+ parkedRef.current = true;
176
325
  // eslint-disable-next-line @eslint-react/set-state-in-effect -- the highlight follows a scroll position, which only exists after layout
177
326
  setActiveIndex(selectedIndex);
178
- }, [isActive, selectedIndex, itemBlockSize, isAtRestRef]);
327
+ }, [isActive, selectedIndex, itemBlockSize, isAtRestRef, scrollToIndex]);
179
328
 
180
329
  // Highlight follows the finger. rAF-throttled: a scroll can fire far more
181
330
  // often than the display refreshes, and this only feeds a repaint.
@@ -276,7 +425,18 @@ export function Wheel({
276
425
  "aria-label": label,
277
426
  "aria-activedescendant": `${id}-${options[activeIndex]?.value}`,
278
427
  tabIndex: 0,
279
- onKeyDown: handleKeyDown,
428
+ onKeyDown: handleKeyDown
429
+ // Read in the capture phase. usePointerDragScroll stops a primary
430
+ // mouse press from bubbling, so that it does not reach BottomSheet's
431
+ // drag. A bubbling handler would never see a mouse, and would keep the
432
+ // last touch.
433
+ ,
434
+ onPointerDownCapture: event => {
435
+ lastPointerRef.current = event.pointerType;
436
+ },
437
+ onWheel: () => {
438
+ lastPointerRef.current = 'wheel';
439
+ },
280
440
  ...stylex.props(styles.scroller, focusOutlineStyles.focusVisible),
281
441
  children: options.map((option, index) => /*#__PURE__*/_jsx("div", {
282
442
  id: `${id}-${option.value}`,
@@ -1 +1 @@
1
- {"version":3,"file":"useDrawerDialogPresence.d.ts","sourceRoot":"","sources":["../../src/Drawer/useDrawerDialogPresence.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAGL,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,cAAc,EACpB,MAAM,OAAO,CAAC;AAaf,KAAK,8BAA8B,GAAG;IACpC,SAAS,EAAE,SAAS,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAAC;IAC/C,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;CAClD,CAAC;AAuDF;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CAAC,EACtC,SAAS,EACT,MAAM,EACN,OAAO,EACP,aAAa,GACd,EAAE,8BAA8B,GAAG,IAAI,CAoEvC"}
1
+ {"version":3,"file":"useDrawerDialogPresence.d.ts","sourceRoot":"","sources":["../../src/Drawer/useDrawerDialogPresence.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAGL,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,cAAc,EACpB,MAAM,OAAO,CAAC;AAcf,KAAK,8BAA8B,GAAG;IACpC,SAAS,EAAE,SAAS,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAAC;IAC/C,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;CAClD,CAAC;AA0DF;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CAAC,EACtC,SAAS,EACT,MAAM,EACN,OAAO,EACP,aAAa,GACd,EAAE,8BAA8B,GAAG,IAAI,CAoEvC"}
@@ -25,6 +25,7 @@
25
25
  */
26
26
  import { useEffect, useRef } from 'react';
27
27
  import { flushSync } from 'react-dom';
28
+ import { notifyTopLayerEntry } from "../Layer/modalOutlet.js";
28
29
 
29
30
  /** Slack past the computed transition before the backstop gives up waiting. */
30
31
  const EXIT_BACKSTOP_BUFFER_MS = 50;
@@ -51,6 +52,9 @@ function showDrawerHost(dialog, isModal) {
51
52
  dialog.showModal();
52
53
  } else if (typeof dialog.showPopover === 'function') {
53
54
  dialog.showPopover();
55
+ // The drawer is now the newest top-layer entry: global hosts shown before
56
+ // it (the toast viewport) re-enter above it, as they do above a modal.
57
+ notifyTopLayerEntry();
54
58
  } else {
55
59
  // Reduced fallback for browsers below the Popover API support floor.
56
60
  dialog.show();
@@ -1 +1 @@
1
- {"version":3,"file":"DropdownMenu.d.ts","sourceRoot":"","sources":["../../src/DropdownMenu/DropdownMenu.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,KAAK,EAAE,EAOZ,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAIf,OAAO,EAAS,KAAK,WAAW,EAAC,MAAM,WAAW,CAAC;AAKnD,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,oBAAoB,CAAC;AA+B9D,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,kCAAkC,CAAC;AAS1C,OAAO,KAAK,EAAC,cAAc,EAAE,cAAc,EAAC,MAAM,mBAAmB,CAAC;AAStE,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AA2L5C;;;;;;;GAOG;AACH,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAChD,qBAAqB,EACnB,MAAM,GACN,SAAS,GACT,YAAY,GACZ,SAAS,GACT,aAAa,GACb,YAAY,GACZ,kBAAkB,GAClB,MAAM,GACN,QAAQ,GACR,KAAK,CACR;IACC;;;;;;OAMG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,6BAA6B;IAC7B,KAAK,EAAE,SAAS,CAAC;IACjB;;;;OAIG;IACH,KAAK,CAAC,EAAE,kBAAkB,EAAE,CAAC;CAC9B;AAED;;;GAGG;AACH,MAAM,W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;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,cAAc,CAAC;IAE3B;;;;;OAKG;IACH,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B;;;;OAIG;IACH,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB;;;OAGG;IACH,MAAM,CAAC,EAAE,SAAS,CAAC;IAEnB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,UAAU,qBAAsB,SAAQ,qBAAqB;IAC3D;;;;;OAKG;IACH,YAAY,CAAC,EAAE,wBAAwB,CAAC;IACxC,KAAK,EAAE,kBAAkB,EAAE,CAAC;IAC5B,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,UAAU,yBAA0B,SAAQ,qBAAqB;IAC/D,YAAY,CAAC,EAAE,SAAS,CAAC;IACzB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,MAAM,MAAM,iBAAiB,GAC3B,qBAAqB,GAAG,yBAAyB,CAAC;AAqvCpD,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,qBA4CpD;yBA5Ce,YAAY"}
@@ -279,6 +279,15 @@ function holdInvokerThroughPress(control, popoverId) {
279
279
  doc.addEventListener('pointerup', onPressEnd, true);
280
280
  doc.addEventListener('pointercancel', onPressEnd, true);
281
281
  }
282
+
283
+ /**
284
+ * The name of a menu opened from a custom trigger: the caller's `aria-label`
285
+ * when it is a non-empty string, else the trigger's own accessible name. The
286
+ * popover and the bottom sheet both name the menu through this.
287
+ */
288
+ function resolveCustomTriggerMenuName(callerLabel, triggerName) {
289
+ return typeof callerLabel === 'string' && callerLabel.trim() !== '' ? callerLabel : triggerName;
290
+ }
282
291
  function DropdownMenuBottomSheet({
283
292
  button: buttonFromProps,
284
293
  renderTrigger,
@@ -340,10 +349,18 @@ function DropdownMenuBottomSheet({
340
349
  useEffect(() => {
341
350
  void preloadMenuBottomSheetActionList();
342
351
  }, []);
352
+ // The control's name is only readable from the DOM once it is rendered.
353
+ const [triggerName, setTriggerName] = useState(undefined);
354
+ useIsomorphicLayoutEffect(() => {
355
+ if (renderTrigger != null && isOpen) {
356
+ setTriggerName(readAccessibleName(buttonRef.current));
357
+ }
358
+ }, [renderTrigger, isOpen]);
359
+ const rootTitle = (renderTrigger != null ? resolveCustomTriggerMenuName(rest['aria-label'], triggerName) : undefined) ?? button.label;
343
360
  const currentSubmenu = submenuPath.at(-1);
344
361
  const currentItems = currentSubmenu?.items ?? items;
345
- const currentTitle = currentSubmenu?.label ?? button.label;
346
- const sheetLabel = typeof currentTitle === 'string' ? currentTitle : button.label;
362
+ const currentTitle = currentSubmenu?.label ?? rootTitle;
363
+ const sheetLabel = typeof currentTitle === 'string' ? currentTitle : rootTitle;
347
364
  const setOpen = useCallback(nextIsOpen => {
348
365
  if (!nextIsOpen) {
349
366
  setSubmenuPath([]);
@@ -734,8 +751,7 @@ function DropdownMenuPopover({
734
751
  // The design system's button names the menu by its label. A custom trigger
735
752
  // names it by reference (or the caller's `aria-label` does), so that name
736
753
  // is read off the control as the menu opens.
737
- const callerMenuLabel = rest['aria-label'];
738
- const menuLabel = renderTrigger != null ? typeof callerMenuLabel === 'string' && callerMenuLabel.trim() !== '' ? callerMenuLabel : triggerName : typeof button.label === 'string' ? button.label : undefined;
754
+ const menuLabel = renderTrigger != null ? resolveCustomTriggerMenuName(rest['aria-label'], triggerName) : typeof button.label === 'string' ? button.label : undefined;
739
755
  const popover = usePopover({
740
756
  onHide: handleLayerHide,
741
757
  onShow: handleLayerShow,
@@ -1 +1 @@
1
- {"version":3,"file":"usePressPin.d.ts","sourceRoot":"","sources":["../../src/Layer/usePressPin.ts"],"names":[],"mappings":"AAIA;;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mC;IACnC,WAAW,EAAE,OAAO,CAAC;IACrB,sCAAsC;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,mDAAmD;IACnD,SAAS,EAAE,MAAM,CAAC;IAClB,0CAA0C;IAC1C,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,2BAA2B;IAC3B,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,sEAAsE;IACtE,MAAM,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IAClC,2FAA2F;IAC3F,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4EAA4E;IAC5E,YAAY,EAAE,iBAAiB,CAAC;IAChC,iEAAiE;IACjE,UAAU,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;CAC3C;AAED,MAAM,WAAW,iBAAiB;IAChC,+EAA+E;IAC/E,eAAe,EAAE,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,KAAK,OAAO,CAAC;IAC1D;;;;OAIG;IACH,UAAU,EAAE,MAAM,OAAO,CAAC;IAC1B,4DAA4D;IAC5D,MAAM,EAAE,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,KAAK,IAAI,CAAC;IAC9C,iEAAiE;IACjE,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB;;;;OAIG;IACH,gBAAgB,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,OAAO,CAAC;IACjD;;;OAGG;IACH,UAAU,EAAE,OAAO,CAAC;IACpB,6EAA6E;IAC7E,KAAK,EAAE,IAAI,CACT,qBAAqB,EACnB,mBAAmB,GACnB,oBAAoB,GACpB,oBAAoB,GACpB,mBAAmB,GACnB,cAAc,CACjB,CAAC;CACH;AAwBD;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,iBAAiB,CAmW1E"}
@@ -96,7 +96,7 @@ export function usePressPin(options) {
96
96
  setIsPinnedState(next);
97
97
  }, []);
98
98
 
99
- // Refs hold the wired trigger and last offered element for a later rewire.
99
+ // The last offered element lets a `triggerBehavior` change rewire it.
100
100
  const triggerRef = useRef(null);
101
101
  const offeredRef = useRef(null);
102
102
  // A primitive: re-attaching the same trigger renders nothing.
@@ -179,9 +179,12 @@ export function usePressPin(options) {
179
179
  }
180
180
  }, [setPinned, announceName, armOutsideDismiss, clearTapOpen]);
181
181
 
182
- // Enter or Space presses a non-native button, which gets no click from the
183
- // browser. A same-task click from its own key handler is that press.
182
+ // A non-native button gets no click from the browser for a key. So Enter
183
+ // presses it on keydown, and Space on keyup, as on a native button. A click
184
+ // with no pointer (`detail` 0) while Space is down, or in a key press's
185
+ // task, is that same press.
184
186
  const keyPressedRef = useRef(false);
187
+ const spaceHeldRef = useRef(false);
185
188
  const handlePress = useCallback(event => {
186
189
  const current = optionsRef.current;
187
190
  if (!current.isEnabled || current.triggerBehavior !== 'toggle') {
@@ -190,23 +193,46 @@ export function usePressPin(options) {
190
193
  // The press stops at its trigger: no label control, link, or submit.
191
194
  event.preventDefault();
192
195
  pressPinClicks.add(event);
193
- if (keyPressedRef.current && event.detail === 0) {
196
+ if (event.detail === 0 && (keyPressedRef.current || spaceHeldRef.current)) {
194
197
  return;
195
198
  }
196
199
  toggle();
197
200
  }, [toggle]);
198
- const handleKeyDown = useCallback(event => {
199
- const current = optionsRef.current;
200
- if (!current.isEnabled || current.triggerBehavior !== 'toggle' || event.repeat || event.isComposing || event.key !== 'Enter' && event.key !== ' ') {
201
- return;
202
- }
203
- event.preventDefault();
201
+ const pressFromKey = useCallback(() => {
204
202
  keyPressedRef.current = true;
205
203
  setTimeout(() => {
206
204
  keyPressedRef.current = false;
207
205
  }, 0);
208
206
  toggle();
209
207
  }, [toggle]);
208
+ const handleKeyDown = useCallback(event => {
209
+ const current = optionsRef.current;
210
+ if (!current.isEnabled || current.triggerBehavior !== 'toggle' || event.isComposing || event.key !== 'Enter' && event.key !== ' ') {
211
+ return;
212
+ }
213
+ // The press replaces the key's own action, such as a page scroll on Space.
214
+ event.preventDefault();
215
+ if (event.repeat) {
216
+ return;
217
+ }
218
+ if (event.key === ' ') {
219
+ spaceHeldRef.current = true;
220
+ return;
221
+ }
222
+ pressFromKey();
223
+ }, [pressFromKey]);
224
+ // Only a Space that went down on the trigger presses it when it comes up.
225
+ const handleKeyUp = useCallback(event => {
226
+ if (event.key !== ' ' || !spaceHeldRef.current) {
227
+ return;
228
+ }
229
+ spaceHeldRef.current = false;
230
+ const current = optionsRef.current;
231
+ if (!current.isEnabled || current.triggerBehavior !== 'toggle') {
232
+ return;
233
+ }
234
+ pressFromKey();
235
+ }, [pressFromKey]);
210
236
  const isHeldOpen = useCallback(() => {
211
237
  const current = optionsRef.current;
212
238
  if (current.triggerBehavior !== 'toggle' || triggerRef.current == null) {
@@ -215,6 +241,8 @@ export function usePressPin(options) {
215
241
  return current.isOpen !== undefined ? current.isOpen && current.isLayerOpen : isPinnedRef.current && current.isLayerOpen;
216
242
  }, []);
217
243
  const handleFocusLeave = useCallback(event => {
244
+ // A Space that comes up after focus left presses nothing.
245
+ spaceHeldRef.current = false;
218
246
  if (!isHeldOpen()) {
219
247
  return false;
220
248
  }
@@ -240,6 +268,7 @@ export function usePressPin(options) {
240
268
  }
241
269
  previous.removeEventListener('click', handlePress);
242
270
  previous.removeEventListener('keydown', handleKeyDown);
271
+ previous.removeEventListener('keyup', handleKeyUp);
243
272
  previous.removeEventListener('focusout', handleFocusLeave);
244
273
  const own = ownStateRef.current;
245
274
  if (own != null) {
@@ -248,7 +277,7 @@ export function usePressPin(options) {
248
277
  }
249
278
  ownStateRef.current = null;
250
279
  triggerRef.current = null;
251
- }, [handlePress, handleKeyDown, handleFocusLeave]);
280
+ }, [handlePress, handleKeyDown, handleKeyUp, handleFocusLeave]);
252
281
 
253
282
  // The element and mode last settled; the same pair again does nothing.
254
283
  const settledRef = useRef(null);
@@ -272,6 +301,7 @@ export function usePressPin(options) {
272
301
  element.addEventListener('click', handlePress);
273
302
  if (element.tagName !== 'BUTTON') {
274
303
  element.addEventListener('keydown', handleKeyDown);
304
+ element.addEventListener('keyup', handleKeyUp);
275
305
  }
276
306
  // Its own focus-leave listener: `focusTrigger="never"` attaches none.
277
307
  element.addEventListener('focusout', handleFocusLeave);
@@ -280,7 +310,7 @@ export function usePressPin(options) {
280
310
  controls: element.getAttribute('aria-controls')
281
311
  };
282
312
  triggerRef.current = element;
283
- }, [unwire, handlePress, handleKeyDown, handleFocusLeave]);
313
+ }, [unwire, handlePress, handleKeyDown, handleKeyUp, handleFocusLeave]);
284
314
  const attach = useCallback(element => {
285
315
  offeredRef.current = element;
286
316
  // Hosts detach and re-attach within one commit, so a detach is not kept.
@@ -1 +1 @@
1
- {"version":3,"file":"useTouchTrigger.d.ts","sourceRoot":"","sources":["../../src/Layer/useTouchTrigger.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,EAIL,KAAK,UAAU,IAAI,eAAe,EAClC,KAAK,YAAY,IAAI,iBAAiB,EACtC,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AASf;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,CAAC;AAExD;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,aAA4B,CAAC;AAE7D,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG;IAC1C,aAAa,EAAE,CAAC,KAAK,EAAE,iBAAiB,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;IAC3D,OAAO,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;CACpD,CAAC;AACF,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,GAAG;IAC9C,aAAa,EAAE,CAAC,KAAK,EAAE,iBAAiB,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;IAC3D,WAAW,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,KAAK,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OAGG;IACH,YAAY,EAAE,OAAO,CAAC;IAEtB,2CAA2C;IAC3C,MAAM,EAAE,OAAO,CAAC;IAEhB,0EAA0E;IAC1E,OAAO,EAAE,MAAM,CAAC;IAEhB,oDAAoD;IACpD,UAAU,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IAE1C,uDAAuD;IACvD,IAAI,EAAE,MAAM,IAAI,CAAC;IAEjB,mCAAmC;IACnC,IAAI,EAAE,MAAM,IAAI,CAAC;CAClB;AAED,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,iBAAiB,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IAEtC;;;;OAIG;IACH,kBAAkB,EAAE,MAAM,OAAO,CAAC;IAElC;;;;OAIG;IACH,kBAAkB,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;IAElD;;;;;;OAMG;IACH,iBAAiB,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC;IAEpD,gFAAgF;IAChF,YAAY,EAAE,MAAM,IAAI,CAAC;CAC1B;AAED;;;;;GAKG;AACH,MAAM,WAAW,6BAA8B,SAAQ,qBAAqB;IAC1E;;;;OAIG;IACH,iBAAiB,EAAE,MAAM,IAAI,CAAC;CAC/B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,sBAAsB,GAC9B,qBAAqB,CASvB;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,sBAAsB,GAC9B,6BAA6B,CA2N/B"}
@@ -248,6 +248,9 @@ export function useTouchTriggerInternal(options) {
248
248
  // pointer-leave, and a controlled one is not ours to close.
249
249
  const isTapOpenRef = useRef(false);
250
250
  const outsideListenerRef = useRef(null);
251
+ // The documents the outside dismissal listens on: the page's, and the
252
+ // trigger's own when it renders in another document, such as an iframe.
253
+ const outsideDocumentsRef = useRef([]);
251
254
  // A touch press on the trigger still waiting for its tap: calling it stops
252
255
  // waiting. The next press, a cancel, the tap itself or unmounting calls it.
253
256
  const forgetPendingTapRef = useRef(null);
@@ -259,8 +262,11 @@ export function useTouchTriggerInternal(options) {
259
262
  return;
260
263
  }
261
264
  outsideListenerRef.current = null;
262
- document.removeEventListener('pointerup', listener, true);
263
- document.removeEventListener('pointercancel', listener, true);
265
+ for (const doc of outsideDocumentsRef.current) {
266
+ doc.removeEventListener('pointerup', listener, true);
267
+ doc.removeEventListener('pointercancel', listener, true);
268
+ }
269
+ outsideDocumentsRef.current = [];
264
270
  }, []);
265
271
 
266
272
  // Capture phase, so a trigger that stops propagation cannot strand an open
@@ -273,6 +279,8 @@ export function useTouchTriggerInternal(options) {
273
279
  if (outsideListenerRef.current != null) {
274
280
  return;
275
281
  }
282
+ const own = triggerRef.current?.ownerDocument ?? document;
283
+ const docs = own === document ? [document] : [document, own];
276
284
  const handleOutsidePointerEnd = event => {
277
285
  const target = event.target;
278
286
  if (target != null) {
@@ -282,7 +290,7 @@ export function useTouchTriggerInternal(options) {
282
290
  return;
283
291
  }
284
292
  // Hover card content is interactive; a tap inside it is not a dismiss.
285
- if (document.getElementById(layerIdRef.current)?.contains(target) === true) {
293
+ if (docs.some(doc => doc.getElementById(layerIdRef.current)?.contains(target) === true)) {
286
294
  return;
287
295
  }
288
296
  }
@@ -290,8 +298,11 @@ export function useTouchTriggerInternal(options) {
290
298
  hideRef.current();
291
299
  };
292
300
  outsideListenerRef.current = handleOutsidePointerEnd;
293
- document.addEventListener('pointerup', handleOutsidePointerEnd, true);
294
- document.addEventListener('pointercancel', handleOutsidePointerEnd, true);
301
+ outsideDocumentsRef.current = docs;
302
+ for (const doc of docs) {
303
+ doc.addEventListener('pointerup', handleOutsidePointerEnd, true);
304
+ doc.addEventListener('pointercancel', handleOutsidePointerEnd, true);
305
+ }
295
306
  }, [triggerRef, disarmOutsideDismiss]);
296
307
  useEffect(() => disarmOutsideDismiss, [disarmOutsideDismiss]);
297
308
  useEffect(() => () => forgetPendingTapRef.current?.(), []);
@@ -70,7 +70,7 @@ export interface ProgressBarProps extends BaseProps<HTMLDivElement> {
70
70
  * When true, renders an animated indeterminate progress indicator.
71
71
  * Use when the progress amount is unknown (e.g. loading, processing).
72
72
  * The `value` and `hasValueLabel` props are ignored in this mode.
73
- * Respects `prefers-reduced-motion` by slowing the animation.
73
+ * Under reduced motion it pulses in place instead of sliding.
74
74
  * @default false
75
75
  */
76
76
  isIndeterminate?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"ProgressBar.d.ts","sourceRoot":"","sources":["../../src/ProgressBar/ProgressBar.tsx"],"names":[],"mappings":"AAiCA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAG5C,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,SAAS,CAAC;AAWnD;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,qBAAqB,CAAC;AAE7D;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;;;;OAMG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,gBAAiB,SAAQ,SAAS,CAAC,cAAc,CAAC;IACjE,wCAAwC;IACxC,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAChC;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;IAC1D;;;OAGG;IACH,OAAO,CAAC,EAAE,kBAAkB,CAAC;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