@astryxdesign/core 0.7.14 → 0.7.15-canary.g79b95eb

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 (131) hide show
  1. package/dist/Calendar/Calendar.d.ts.map +1 -1
  2. package/dist/Calendar/Calendar.js +11 -2
  3. package/dist/Calendar/getInitialFocusDate.d.ts +8 -3
  4. package/dist/Calendar/getInitialFocusDate.d.ts.map +1 -1
  5. package/dist/Calendar/getInitialFocusDate.js +42 -7
  6. package/dist/CheckboxInput/CheckboxInput.d.ts.map +1 -1
  7. package/dist/CheckboxInput/CheckboxInput.js +9 -4
  8. package/dist/CheckboxList/CheckboxListItem.d.ts.map +1 -1
  9. package/dist/CheckboxList/CheckboxListItem.js +3 -8
  10. package/dist/DateInput/useTypedDate.d.ts.map +1 -1
  11. package/dist/DateInput/useTypedDate.js +3 -2
  12. package/dist/DateTimeInput/DateTimeInput.d.ts.map +1 -1
  13. package/dist/DateTimeInput/DateTimeInput.js +6 -3
  14. package/dist/DateTimeInput/NativeDateSegment.d.ts.map +1 -1
  15. package/dist/DateTimeInput/NativeDateSegment.js +23 -9
  16. package/dist/DateTimeInput/NativeTimeSegment.d.ts.map +1 -1
  17. package/dist/DateTimeInput/NativeTimeSegment.js +22 -8
  18. package/dist/Drawer/Drawer.d.ts.map +1 -1
  19. package/dist/Drawer/Drawer.js +7 -5
  20. package/dist/DropdownMenu/MenuBottomSheetActionList.d.ts.map +1 -1
  21. package/dist/DropdownMenu/MenuBottomSheetActionList.js +5 -1
  22. package/dist/Item/Item.d.ts +1 -1
  23. package/dist/Item/Item.d.ts.map +1 -1
  24. package/dist/Item/Item.js +4 -2
  25. package/dist/Link/useLinkify.d.ts.map +1 -1
  26. package/dist/Link/useLinkify.js +3 -2
  27. package/dist/List/List.d.ts +4 -1
  28. package/dist/List/List.d.ts.map +1 -1
  29. package/dist/Markdown/Markdown.d.ts.map +1 -1
  30. package/dist/Markdown/Markdown.js +8 -0
  31. package/dist/RadioList/RadioListItem.d.ts.map +1 -1
  32. package/dist/RadioList/RadioListItem.js +19 -4
  33. package/dist/SegmentedControl/useSegmentedSelectionMotion.d.ts +43 -15
  34. package/dist/SegmentedControl/useSegmentedSelectionMotion.d.ts.map +1 -1
  35. package/dist/SegmentedControl/useSegmentedSelectionMotion.js +108 -18
  36. package/dist/SegmentedControl/useSegmentedTouchTracking.d.ts.map +1 -1
  37. package/dist/SegmentedControl/useSegmentedTouchTracking.js +5 -0
  38. package/dist/Table/plugins/sortable/useTableSortableState.d.ts.map +1 -1
  39. package/dist/Table/plugins/sortable/useTableSortableState.js +7 -3
  40. package/dist/Token/Token.d.ts.map +1 -1
  41. package/dist/Token/Token.js +2 -0
  42. package/dist/Tokenizer/Tokenizer.d.ts.map +1 -1
  43. package/dist/Tokenizer/Tokenizer.js +85 -12
  44. package/dist/astryx.css +11 -10
  45. package/dist/gestures/GestureHost.d.ts +5 -0
  46. package/dist/gestures/GestureHost.d.ts.map +1 -1
  47. package/dist/gestures/GestureHost.js +54 -28
  48. package/dist/hooks/menuPressGesture.d.ts +39 -2
  49. package/dist/hooks/menuPressGesture.d.ts.map +1 -1
  50. package/dist/hooks/menuPressGesture.js +92 -5
  51. package/dist/hooks/scrollOwnerRegistry.d.ts +0 -1
  52. package/dist/hooks/scrollOwnerRegistry.d.ts.map +1 -1
  53. package/dist/hooks/scrollOwnerRegistry.js +4 -1
  54. package/dist/hooks/useClickableContainer.d.ts +6 -4
  55. package/dist/hooks/useClickableContainer.d.ts.map +1 -1
  56. package/dist/hooks/useClickableContainer.js +11 -8
  57. package/dist/hooks/useFocusTrap.d.ts.map +1 -1
  58. package/dist/hooks/useFocusTrap.js +6 -0
  59. package/dist/hooks/useMenuPress.d.ts.map +1 -1
  60. package/dist/hooks/useMenuPress.js +35 -2
  61. package/dist/hooks/useStreamingText.d.ts.map +1 -1
  62. package/dist/hooks/useStreamingText.js +38 -23
  63. package/dist/i18n/generated-english/DateInput/useTypedDate.generated.js +2 -2
  64. package/dist/i18n/generated-locales/en.generated.js +2 -2
  65. package/dist/i18n/generated-locales/pseudo.generated.js +2 -2
  66. package/dist/motion/uikit/segmented.d.ts +35 -7
  67. package/dist/motion/uikit/segmented.d.ts.map +1 -1
  68. package/dist/motion/uikit/segmented.js +39 -11
  69. package/dist/privateAttributes/press.stylex.d.ts.map +1 -1
  70. package/dist/privateAttributes/press.stylex.js +1 -1
  71. package/dist/privateAttributes/pressBox.stylex.d.ts +12 -4
  72. package/dist/privateAttributes/pressBox.stylex.d.ts.map +1 -1
  73. package/dist/privateAttributes/pressBox.stylex.js +21 -4
  74. package/dist/privateAttributes/tokenRemove.stylex.d.ts +5 -0
  75. package/dist/privateAttributes/tokenRemove.stylex.d.ts.map +1 -0
  76. package/dist/privateAttributes/tokenRemove.stylex.js +25 -0
  77. package/dist/theme/defineTheme.d.ts +0 -1
  78. package/dist/theme/defineTheme.d.ts.map +1 -1
  79. package/dist/utils/inputAge.d.ts +5 -2
  80. package/dist/utils/inputAge.d.ts.map +1 -1
  81. package/dist/utils/inputAge.js +4 -1
  82. package/dist/utils/pressFeedback.d.ts.map +1 -1
  83. package/dist/utils/pressFeedback.js +60 -9
  84. package/locales/en.json +3 -3
  85. package/locales/pseudo.json +2 -2
  86. package/package.json +5 -5
  87. package/src/Calendar/Calendar.tsx +11 -1
  88. package/src/Calendar/getInitialFocusDate.ts +70 -8
  89. package/src/CheckboxInput/CheckboxInput.doc.mjs +16 -2
  90. package/src/CheckboxInput/CheckboxInput.tsx +32 -23
  91. package/src/CheckboxList/CheckboxList.doc.mjs +1 -1
  92. package/src/CheckboxList/CheckboxListItem.tsx +3 -6
  93. package/src/DateInput/useTypedDate.ts +9 -6
  94. package/src/DateTimeInput/DateTimeInput.tsx +7 -3
  95. package/src/DateTimeInput/NativeDateSegment.tsx +28 -10
  96. package/src/DateTimeInput/NativeTimeSegment.tsx +19 -9
  97. package/src/Drawer/Drawer.tsx +7 -5
  98. package/src/DropdownMenu/MenuBottomSheetActionList.tsx +3 -0
  99. package/src/Item/Item.doc.mjs +2 -1
  100. package/src/Item/Item.tsx +7 -3
  101. package/src/Link/useLinkify.tsx +7 -9
  102. package/src/List/List.doc.mjs +9 -21
  103. package/src/List/List.tsx +4 -1
  104. package/src/List/ListItem.doc.mjs +4 -2
  105. package/src/Markdown/Markdown.tsx +7 -0
  106. package/src/RadioList/RadioListItem.tsx +60 -30
  107. package/src/SegmentedControl/SegmentedControl.doc.mjs +3 -3
  108. package/src/SegmentedControl/useSegmentedSelectionMotion.ts +115 -19
  109. package/src/SegmentedControl/useSegmentedTouchTracking.ts +5 -0
  110. package/src/Table/plugins/sortable/useTableSortableState.tsx +5 -1
  111. package/src/Token/Token.tsx +2 -0
  112. package/src/Tokenizer/Tokenizer.tsx +102 -7
  113. package/src/gestures/GestureHost.ts +62 -32
  114. package/src/hooks/menuPressGesture.ts +116 -9
  115. package/src/hooks/scrollOwnerRegistry.ts +8 -1
  116. package/src/hooks/useClickableContainer.ts +11 -8
  117. package/src/hooks/useFocusTrap.ts +6 -0
  118. package/src/hooks/useMenuPress.ts +32 -2
  119. package/src/hooks/useStreamingText.ts +30 -25
  120. package/src/i18n/generated-english/DateInput/useTypedDate.generated.ts +2 -2
  121. package/src/i18n/generated-locales/en.generated.ts +2 -2
  122. package/src/i18n/generated-locales/pseudo.generated.ts +2 -2
  123. package/src/motion/MEASUREMENTS.md +2 -3
  124. package/src/motion/uikit/segmented.ts +35 -10
  125. package/src/privateAttributes/press.stylex.ts +2 -8
  126. package/src/privateAttributes/pressBox.stylex.ts +23 -4
  127. package/src/privateAttributes/tokenRemove.stylex.ts +27 -0
  128. package/src/theme/defineTheme.ts +0 -1
  129. package/src/theme/useThemeName.doc.mjs +69 -0
  130. package/src/utils/inputAge.ts +5 -2
  131. package/src/utils/pressFeedback.ts +80 -9
@@ -52,8 +52,41 @@ registerBoxHold();
52
52
  // that paints it. See interactionOverlay.stylex.ts.
53
53
  const pressedOverlayImage = 'var(--_press-paint-image)';
54
54
 
55
- // The mouse press's paint, declared on the row and inherited by the layer
56
- // over the circle. Internal: not a theme hook.
55
+ /** Written by the press controller while the row is pressed. */
56
+ const PRESSED_ON = '[data-astryx-press="on"]';
57
+ /** Written by the press controller for the press's release. */
58
+ const PRESSED_FADING = '[data-astryx-press="fading"]';
59
+
60
+ /**
61
+ * The nested controls that keep their own press, each at `:active`. It is
62
+ * INTERACTIVE_SELECTORS (hooks/useClickableContainer.ts), which StyleX cannot
63
+ * import, less the read-only ones. The row's own radio is the row's action,
64
+ * so its press is the row's. CSS cannot tell it from a nested radio input, so
65
+ * a nested one presses the circle too. RadioListItem.press.source-build.test.mjs
66
+ * keeps the two lists equal.
67
+ */
68
+ const NESTED_CONTROL_ACTIVE =
69
+ 'button:not([aria-readonly="true"]):active,' +
70
+ 'a:not([aria-readonly="true"]):active,' +
71
+ 'input:not([type="radio"],[aria-readonly="true"]):active,' +
72
+ 'select:not([aria-readonly="true"]):active,' +
73
+ 'textarea:not([aria-readonly="true"]):active,' +
74
+ '[role="button"]:not([aria-readonly="true"]):active,' +
75
+ '[role="link"]:not([aria-readonly="true"]):active,' +
76
+ '[role="checkbox"]:not([aria-readonly="true"]):active,' +
77
+ '[role="radio"]:not([aria-readonly="true"]):active,' +
78
+ '[role="switch"]:not([aria-readonly="true"]):active,' +
79
+ '[role="tab"]:not([aria-readonly="true"]):active,' +
80
+ '[role="menuitem"]:not([aria-readonly="true"]):active,' +
81
+ '[role="option"]:not([aria-readonly="true"]):active,' +
82
+ '[role="combobox"]:not([aria-readonly="true"]):active,' +
83
+ '[role="listbox"]:not([aria-readonly="true"]):active,' +
84
+ '[role="slider"]:not([aria-readonly="true"]):active,' +
85
+ '[role="spinbutton"]:not([aria-readonly="true"]):active,' +
86
+ '[data-pressable-container]:not([aria-readonly="true"]):active';
87
+
88
+ // The paint of a press the controller does not paint, declared on the row
89
+ // and inherited by the layer over the circle. Internal: not a theme hook.
57
90
  const ROW_PRESS = '--_radio-row-press';
58
91
 
59
92
  const styles = stylex.create({
@@ -65,17 +98,18 @@ const styles = stylex.create({
65
98
  flexShrink: 0,
66
99
  isolation: 'isolate',
67
100
  },
68
- // The row remains the large press target, but nested links and buttons keep
69
- // their independent action and do not make the radio appear pressed: the
101
+ // The row remains the large press target, but nested controls keep their
102
+ // independent action and do not make the radio appear pressed: the
70
103
  // row declares the mouse press's paint (`rowStyles.press`) and this layer
71
104
  // reads it. This owner-drawn layer also survives a theme replacing the
72
105
  // indicator component.
73
- // Two pointers, two press models (see interactionOverlay.stylex.ts): a
74
- // mouse keeps `:active`; under a coarse pointer that arm is dropped and the
75
- // touch press controller writes `data-astryx-press` on the row, which this layer
76
- // reads off the same scope marker as the hover tint. The controller paints
77
- // the innermost pressable, so a nested link or button takes the press
78
- // itself and the row never carries the attribute for it.
106
+ // The press controller writes its press attribute on the row for every
107
+ // pointer: a finger, a mouse and a pen. This layer reads it off the same
108
+ // scope marker as the hover tint. The controller paints the innermost pressable.
109
+ // A press on a control nested in the row is that control's. The row's
110
+ // container rule (cancelNestedTouchPress) ends the row's paint at once.
111
+ // `:active` paints only a press the controller does not paint, and under a
112
+ // coarse pointer it is dropped.
79
113
  indicatorPressOverlay: {
80
114
  '::after': {
81
115
  content: '""',
@@ -84,21 +118,16 @@ const styles = stylex.create({
84
118
  borderRadius: radiusVars['--radius-full'],
85
119
  pointerEvents: 'none',
86
120
  backgroundColor: `var(${ROW_PRESS}, transparent)`,
87
- // The touch press, as an image layer over the colour: an image change is
88
- // discrete, so no transition can delay the onset, and the strength the
89
- // row's `pressedAlpha` arms own (1 while on, 1 → 0 over the release) is
90
- // what moves. Coarse pointers only, like the drop above.
121
+ // The controller's press paints as an image layer over the colour. An
122
+ // image change is discrete, so no transition can delay the onset. Only
123
+ // the strength moves: the row's `pressedAlpha` arms set it to 1 while
124
+ // on, and 1 → 0 over the release. This holds for every pointer, because
125
+ // the controller writes the attribute only for a press it paints.
91
126
  backgroundImage: {
92
127
  default: null,
93
- [stylex.when.ancestor('[data-astryx-press="on"]', indicatorScope)]: {
94
- default: null,
95
- '@media (pointer: coarse)': pressedOverlayImage,
96
- },
97
- [stylex.when.ancestor('[data-astryx-press="fading"]', indicatorScope)]:
98
- {
99
- default: null,
100
- '@media (pointer: coarse)': pressedOverlayImage,
101
- },
128
+ [stylex.when.ancestor(PRESSED_ON, indicatorScope)]: pressedOverlayImage,
129
+ [stylex.when.ancestor(PRESSED_FADING, indicatorScope)]:
130
+ pressedOverlayImage,
102
131
  },
103
132
  },
104
133
  },
@@ -158,16 +187,17 @@ const rowStyles = stylex.create({
158
187
  // hovered row look identical by default (a theme can restyle either).
159
188
  backgroundColor: 'transparent',
160
189
  },
161
- // The mouse press (a finger's lives on `data-astryx-press`): the row is
162
- // pressed, but not through a nested link or button, which keep their own
163
- // action. The `:has()` is on the row itself and reaches no descendant
164
- // selector, so a change inside the row re-checks the row alone; the circle's
165
- // layer reads the paint through inheritance rather than a relation that
166
- // would restyle everything under the row.
190
+ // A press the controller does not paint: the controller's own press lives
191
+ // on its attribute. The row is pressed, but not through a nested control.
192
+ // Such a control keeps its own press, as the row's container rule decides
193
+ // for the controller. The `:has()` is on the row itself and reaches no
194
+ // descendant selector. So a change inside the row re-checks the row alone.
195
+ // The circle's layer reads the paint through inheritance. A relation would
196
+ // restyle everything under the row.
167
197
  press: {
168
198
  [ROW_PRESS]: {
169
199
  default: null,
170
- ':active:not(:has(a:active,button:active,[role="button"]:active,[role="link"]:active))':
200
+ [`:active:not(${PRESSED_ON},${PRESSED_FADING}):not(:has(${NESTED_CONTROL_ACTIVE}))`]:
171
201
  {
172
202
  default: colorVars['--color-overlay-pressed'],
173
203
  '@media (pointer: coarse)': 'transparent',
@@ -168,7 +168,7 @@ function WorkspaceCard() {
168
168
  usage: {
169
169
  anatomy,
170
170
  description:
171
- 'A segmented button group that allows users to make a single selection from a small set of mutually exclusive options. Use SegmentedControl when all options should be visible at once and the selection controls a value or mode, not page navigation. Under a finger, on a touch device (a coarse primary pointer), the selection slides to the new segment, whether a tap, an arrow key or a new value moved it; with Reduce Motion nothing travels: the old selection fades out as the new one fades in. There, dragging the selected segment carries the selection along with the selected label’s colour following it, and the segment under the finger is chosen when it lets go; a tap selects through the browser’s click; a pressed segment shows the shared pressed overlay, and nothing lifts or dims. A drag that drifts off the control still chooses by its position along it. Going back to the selected segment, or Escape, changes nothing. With a mouse or a pen every change, a click included, slides on the theme’s duration and easing, and dragging the selected segment carries it as a finger does.',
171
+ 'A segmented button group that allows users to make a single selection from a small set of mutually exclusive options. Use SegmentedControl when all options should be visible at once and the selection controls a value or mode, not page navigation. Under a finger, on a touch device (a coarse primary pointer), the selection slides to the new segment, whether a tap, an arrow key or a new value moved it; with Reduce Motion nothing travels: the old selection fades out as the new one fades in. There, pressing the selected segment lifts it, and dragging it carries the selection along with the selected label’s colour following it, and the segment under the finger is chosen when it lets go; a tap selects through the browser’s click; a pressed unselected segment shows the shared pressed overlay, and nothing dims. A drag that drifts off the control still chooses by its position along it. Going back to the selected segment, or Escape, changes nothing. With a mouse or a pen every change, a click included, slides on the theme’s duration and easing, and dragging the selected segment carries it as a finger does.',
172
172
  accessibility: [
173
173
  {
174
174
  name: 'Text label',
@@ -240,7 +240,7 @@ export const docsZh = {
240
240
  usage: {
241
241
  anatomy,
242
242
  description:
243
- 'A segmented button group that allows users to make a single selection from a small set of mutually exclusive options. Use SegmentedControl when all options should be visible at once and the selection controls a value or mode, not page navigation. Under a finger, on a touch device (a coarse primary pointer), the selection slides to the new segment, whether a tap, an arrow key or a new value moved it; with Reduce Motion nothing travels: the old selection fades out as the new one fades in. There, dragging the selected segment carries the selection along with the selected label’s colour following it, and the segment under the finger is chosen when it lets go; a tap selects through the browser’s click; a pressed segment shows the shared pressed overlay, and nothing lifts or dims. A drag that drifts off the control still chooses by its position along it. Going back to the selected segment, or Escape, changes nothing. With a mouse or a pen every change, a click included, slides on the theme’s duration and easing, and dragging the selected segment carries it as a finger does.',
243
+ 'A segmented button group that allows users to make a single selection from a small set of mutually exclusive options. Use SegmentedControl when all options should be visible at once and the selection controls a value or mode, not page navigation. Under a finger, on a touch device (a coarse primary pointer), the selection slides to the new segment, whether a tap, an arrow key or a new value moved it; with Reduce Motion nothing travels: the old selection fades out as the new one fades in. There, pressing the selected segment lifts it, and dragging it carries the selection along with the selected label’s colour following it, and the segment under the finger is chosen when it lets go; a tap selects through the browser’s click; a pressed unselected segment shows the shared pressed overlay, and nothing dims. A drag that drifts off the control still chooses by its position along it. Going back to the selected segment, or Escape, changes nothing. With a mouse or a pen every change, a click included, slides on the theme’s duration and easing, and dragging the selected segment carries it as a finger does.',
244
244
  bestPractices: [
245
245
  {guidance: true, description: 'Use for switching between 2–5 mutually exclusive views or modes where all options should be visible.'},
246
246
  {guidance: true, description: 'Provide a descriptive label for the control to ensure the group is accessible to screen readers.'},
@@ -256,7 +256,7 @@ export const docsDense = {
256
256
  usage: {
257
257
  anatomy,
258
258
  description:
259
- 'A segmented button group that allows users to make a single selection from a small set of mutually exclusive options. Use SegmentedControl when all options should be visible at once and the selection controls a value or mode, not page navigation. Under a finger, on a touch device (a coarse primary pointer), the selection slides to the new segment, whether a tap, an arrow key or a new value moved it; with Reduce Motion nothing travels: the old selection fades out as the new one fades in. There, dragging the selected segment carries the selection along with the selected label’s colour following it, and the segment under the finger is chosen when it lets go; a tap selects through the browser’s click; a pressed segment shows the shared pressed overlay, and nothing lifts or dims. A drag that drifts off the control still chooses by its position along it. Going back to the selected segment, or Escape, changes nothing. With a mouse or a pen every change, a click included, slides on the theme’s duration and easing, and dragging the selected segment carries it as a finger does.',
259
+ 'A segmented button group that allows users to make a single selection from a small set of mutually exclusive options. Use SegmentedControl when all options should be visible at once and the selection controls a value or mode, not page navigation. Under a finger, on a touch device (a coarse primary pointer), the selection slides to the new segment, whether a tap, an arrow key or a new value moved it; with Reduce Motion nothing travels: the old selection fades out as the new one fades in. There, pressing the selected segment lifts it, and dragging it carries the selection along with the selected label’s colour following it, and the segment under the finger is chosen when it lets go; a tap selects through the browser’s click; a pressed unselected segment shows the shared pressed overlay, and nothing dims. A drag that drifts off the control still chooses by its position along it. Going back to the selected segment, or Escape, changes nothing. With a mouse or a pen every change, a click included, slides on the theme’s duration and easing, and dragging the selected segment carries it as a finger does.',
260
260
  bestPractices: [
261
261
  {guidance: true, description: 'Use for switching between 2–5 mutually exclusive views or modes where all options should be visible.'},
262
262
  {guidance: true, description: 'Provide a descriptive label for the control to ensure the group is accessible to screen readers.'},
@@ -42,6 +42,7 @@ import {observeResize} from '../utils/sharedResizeObserver';
42
42
  import {titleOfSegment} from '../privateAttributes/segmentTitle.stylex';
43
43
  import {mapProgress, mapRange} from '../motion/progress';
44
44
  import {easedProgress, readThemeTiming} from '../motion/themeTiming';
45
+ import {shadowVars} from '../theme/tokens.stylex';
45
46
  import {useSegmentedTouchTracking} from './useSegmentedTouchTracking';
46
47
 
47
48
  /** The segments, in DOM order. */
@@ -100,6 +101,13 @@ export const LAYER_GEOMETRY: ReadonlyArray<string> = [
100
101
  'visibility',
101
102
  ];
102
103
 
104
+ /**
105
+ * The lifted lens's edge: the theme's low elevation, as on Switch's lifted
106
+ * thumb. The lens copies the selected surface, which can match the page.
107
+ * Without an edge, a lifted lens hides the track around it.
108
+ */
109
+ const LIFTED_SHADOW = shadowVars['--shadow-low'];
110
+
103
111
  /** The custom property on the radiogroup that sets `property` of `layer`. */
104
112
  export function layerVariable(layer: Layer, property: string): string {
105
113
  return `--_segmented-${layer}-${property.replace(/^-+/, '')}`;
@@ -398,11 +406,13 @@ function defaultNow(): number {
398
406
  * once.
399
407
  *
400
408
  * Under a finger:
401
- * - A theme role owns a pressed thumb's lift, so a press on the selected
402
- * segment lifts nothing here.
403
- * - A drag from the selected segment carries the lens at its resting size.
404
- * Its center chases the finger, at most `dragOvershoot` past the end
405
- * segments.
409
+ * - A press on the selected segment lifts the lens, as UIKit's does. It
410
+ * grows by `liftGrowth` on the `lift` spring and shrinks back on the same
411
+ * spring after the release. A pen's press lifts it too. While lifted it
412
+ * carries the theme's low elevation shadow, so the track stays visible
413
+ * around it.
414
+ * - A drag from the selected segment carries the lifted lens. Its center
415
+ * chases the finger, at most `dragOvershoot` past the end segments.
406
416
  * - The selected title's color follows the lens's center. It moves to a
407
417
  * neighbor only once the center is a quarter of that segment past the
408
418
  * boundary. Every title keeps its weight until the lift.
@@ -422,9 +432,9 @@ function defaultNow(): number {
422
432
  * from the selected segment carries the lens on the pointer itself.
423
433
  *
424
434
  * Under Reduced Motion, a held lens still follows the pointer: that is direct
425
- * movement, not a transition. Nothing else chases, travels or scales. The lens
426
- * fades in at the new segment while ::after, painted with the old surface,
427
- * fades out in place. With a fine pointer under Reduce Motion, a change shows
435
+ * movement, not a transition. Nothing else chases, travels, lifts or scales.
436
+ * The lens fades in at the new segment while ::after, painted with the old
437
+ * surface, fades out in place. With a fine pointer under Reduce Motion, a change shows
428
438
  * through the theme's transition.
429
439
  */
430
440
  export class SegmentedSelectionMotion {
@@ -448,6 +458,13 @@ export class SegmentedSelectionMotion {
448
458
  private readonly running = new Set<MotionHandle>();
449
459
  /** A finger holds the lens: a drag from the selected segment carries it. */
450
460
  private isHeld = false;
461
+ /** The held lens grew by `liftGrowth`; its settle shrinks it back. */
462
+ private isLifted = false;
463
+ /**
464
+ * The lifted lens wears the theme's elevation. The hand-back clears this
465
+ * shadow with the lens, so a commit's repaint keeps it until then.
466
+ */
467
+ private hasLiftedEdge = false;
451
468
  /**
452
469
  * The touch presentation applies (a coarse primary pointer), so every
453
470
  * change slides on UIKit's springs. When it is off, a change slides on the
@@ -571,7 +588,7 @@ export class SegmentedSelectionMotion {
571
588
  if (carried != null && carried.segment === destination) {
572
589
  if (carried.hidden !== destination) {
573
590
  showSurface(carried.hidden);
574
- paintLayer(track, 'lens', destination);
591
+ this.paintLens(track, destination);
575
592
  hideSurface(destination);
576
593
  carried.hidden = destination;
577
594
  }
@@ -653,16 +670,78 @@ export class SegmentedSelectionMotion {
653
670
  };
654
671
  }
655
672
 
673
+ /**
674
+ * The press tracker highlighted the press, as UIControl does: at once, or
675
+ * after a scroller's content delay. A press on the selected segment lifts
676
+ * the lens then. A touch the page scrolls first lifts nothing.
677
+ */
678
+ highlighted(): void {
679
+ if (this.touch?.carriesLens === true) {
680
+ this.lift();
681
+ }
682
+ }
683
+
684
+ /**
685
+ * The lens binds on the selected segment and grows by `liftGrowth` on the
686
+ * `lift` spring. A slide still on its way goes on to that segment on the
687
+ * slide spring, at its own speed. Any pointer lifts it under the touch
688
+ * presentation, as Switch's thumb does. A fine primary pointer and Reduce
689
+ * Motion keep it at its resting size.
690
+ */
691
+ private lift(): void {
692
+ if (
693
+ this.isLifted ||
694
+ !this.isPresenting ||
695
+ this.animator.reducedMotion() !== 'off'
696
+ ) {
697
+ return;
698
+ }
699
+ this.hold();
700
+ const carried = this.carried;
701
+ if (!this.isHeld || carried == null) {
702
+ return;
703
+ }
704
+ const [width, height] = segmentedControl.liftGrowth;
705
+ const lifted = {
706
+ scaleX: (carried.box.width + width) / carried.box.width,
707
+ scaleY: (carried.box.height + height) / carried.box.height,
708
+ };
709
+ this.isLifted = true;
710
+ this.hasLiftedEdge = true;
711
+ const position = {x: 0} as const;
712
+ this.springLens(position, this.springFrom(position, 'selection'));
713
+ this.springLens(lifted, this.springFrom(lifted, 'lift'));
714
+ this.showLiftedEdge();
715
+ }
716
+
717
+ /** The lifted lens's edge: the theme's low elevation. */
718
+ private showLiftedEdge(): void {
719
+ this.track?.style.setProperty(
720
+ layerVariable('lens', 'box-shadow'),
721
+ LIFTED_SHADOW,
722
+ );
723
+ }
724
+
725
+ /** Paints the lens with `segment`'s surface; a lifted lens keeps its edge. */
726
+ private paintLens(track: HTMLElement, segment: HTMLElement): void {
727
+ paintLayer(track, 'lens', segment);
728
+ if (this.hasLiftedEdge) {
729
+ this.showLiftedEdge();
730
+ }
731
+ }
732
+
656
733
  /**
657
734
  * The finger moved to `clientX`. A drag from the selected segment carries
658
- * the lens at its resting size. A touch elsewhere leaves the lens alone,
659
- * and that segment shows the shared pressed overlay.
735
+ * the lens. A touch elsewhere leaves the lens alone, and that segment shows
736
+ * the shared pressed overlay.
660
737
  */
661
738
  drag(clientX: number): void {
662
739
  const touch = this.touch;
663
740
  if (touch == null || !touch.carriesLens) {
664
741
  return;
665
742
  }
743
+ // A drag that starts before the highlight lifts the lens as well.
744
+ this.lift();
666
745
  this.hold();
667
746
  if (!this.isHeld) {
668
747
  return;
@@ -672,9 +751,9 @@ export class SegmentedSelectionMotion {
672
751
  }
673
752
 
674
753
  /**
675
- * The first move of a drag from the selected segment binds the lens there,
676
- * at its resting size. Under Reduced Motion too: the lens follows the hand,
677
- * and only the release cross-fades.
754
+ * A finger's press on the selected segment, or the first move of a drag
755
+ * from it, binds the lens there. Under Reduced Motion too: the lens follows
756
+ * the hand, and only the release cross-fades.
678
757
  */
679
758
  private hold(): void {
680
759
  const touch = this.touch;
@@ -928,6 +1007,8 @@ export class SegmentedSelectionMotion {
928
1007
  settle(): void {
929
1008
  this.endLeaving();
930
1009
  this.isHeld = false;
1010
+ this.isLifted = false;
1011
+ this.hasLiftedEdge = false;
931
1012
  this.pending = null;
932
1013
  const carried = this.carried;
933
1014
  if (carried != null) {
@@ -1171,7 +1252,7 @@ export class SegmentedSelectionMotion {
1171
1252
  if (this.abandoned.has(paint)) {
1172
1253
  showSurface(paint);
1173
1254
  }
1174
- paintLayer(track, 'lens', paint);
1255
+ this.paintLens(track, paint);
1175
1256
  hideSurface(paint);
1176
1257
  this.abandoned.delete(paint);
1177
1258
  }
@@ -1193,12 +1274,14 @@ export class SegmentedSelectionMotion {
1193
1274
  /** A spring transition that keeps the captured velocities of `values`. */
1194
1275
  private springFrom(
1195
1276
  values: MotionValues,
1196
- kind: 'selection' | 'tracking',
1277
+ kind: 'selection' | 'tracking' | 'lift',
1197
1278
  ): SpringTransition {
1198
1279
  const spring =
1199
1280
  kind === 'selection'
1200
1281
  ? segmentedControl.selectionSpring
1201
- : springs.fingerTracking;
1282
+ : kind === 'lift'
1283
+ ? segmentedControl.lift
1284
+ : springs.fingerTracking;
1202
1285
  const velocity: Record<string, number> = {};
1203
1286
  for (const key of Object.keys(values) as (keyof typeof this.velocity)[]) {
1204
1287
  const v = this.velocity[key];
@@ -1215,11 +1298,24 @@ export class SegmentedSelectionMotion {
1215
1298
 
1216
1299
  /**
1217
1300
  * The lens settles at its resting place on `segment`. Under a finger it
1218
- * springs on the slide spring. Under a fine pointer it takes the theme's
1219
- * duration and easing, as the segments' own transition does.
1301
+ * springs on the slide spring, and a lifted lens shrinks back on the lift's.
1302
+ * Under a fine pointer it takes the theme's duration and easing, as the
1303
+ * segments' own transition does.
1220
1304
  */
1221
1305
  private settleLens(segment: HTMLElement, options: AnimateOptions): void {
1222
1306
  const rest = {x: 0, scaleX: 1, scaleY: 1} as const;
1307
+ if (this.isPresenting && this.isLifted) {
1308
+ this.isLifted = false;
1309
+ const position = {x: 0} as const;
1310
+ const size = {scaleX: 1, scaleY: 1} as const;
1311
+ this.springLens(
1312
+ position,
1313
+ this.springFrom(position, 'selection'),
1314
+ options,
1315
+ );
1316
+ this.springLens(size, this.springFrom(size, 'lift'), options);
1317
+ return;
1318
+ }
1223
1319
  if (this.isPresenting) {
1224
1320
  this.springLens(rest, this.springFrom(rest, 'selection'), options);
1225
1321
  return;
@@ -255,6 +255,11 @@ export function useSegmentedTouchTracking(
255
255
  const attachRef = isEnabled ? trackRef : DETACHED;
256
256
  usePressTracker(attachRef, {
257
257
  isEnabled: () => isEnabled,
258
+ onHighlightChange: isHighlighted => {
259
+ if (isHighlighted) {
260
+ motion.highlighted();
261
+ }
262
+ },
258
263
  onControlEvent: (event, touch) => {
259
264
  const track = trackRef.current;
260
265
  if (track == null) {
@@ -233,6 +233,10 @@ function sortData<
233
233
  // Hook
234
234
  // =============================================================================
235
235
 
236
+ // One options object, so the collator, and the sorted data with it, survive
237
+ // a render that changes neither the locale nor the sort.
238
+ const COLLATOR_OPTIONS: Intl.CollatorOptions = {numeric: true};
239
+
236
240
  /**
237
241
  * useTableSortableState — manages sort state and applies local sort to data.
238
242
  *
@@ -266,7 +270,7 @@ export function useTableSortableState<
266
270
  allowUnsortedState,
267
271
  isMultiSortEnabled,
268
272
  } = config;
269
- const collator = useCollator({numeric: true});
273
+ const collator = useCollator(COLLATOR_OPTIONS);
270
274
 
271
275
  // Internal state (used in uncontrolled mode)
272
276
  const [internalSort, setInternalSort] =
@@ -49,6 +49,7 @@ import {
49
49
  useComponentTranslator,
50
50
  } from '../i18n/useComponentTranslator';
51
51
  import english from '../i18n/generated-english/Token/Token.generated';
52
+ import {tokenRemoveProps} from '../privateAttributes/tokenRemove.stylex';
52
53
 
53
54
  registerEnglishFallback(english);
54
55
 
@@ -337,6 +338,7 @@ export function Token({
337
338
  aria-label={t('@astryx.token.remove', {
338
339
  label: naming?.removeName ?? label,
339
340
  })}
341
+ {...tokenRemoveProps}
340
342
  onClick={e => {
341
343
  e.stopPropagation();
342
344
  onRemove(e);
@@ -118,6 +118,8 @@ import type {
118
118
  import {composeEventHandlers, mergeProps} from '../utils';
119
119
  import {getInputARIA, joinAriaIDs} from '../utils/inputAria';
120
120
  import {isFocusDetached} from '../utils/isFocusDetached';
121
+ import {removeControlOf} from '../privateAttributes/tokenRemove.stylex';
122
+ import {useTapStop} from '../Layer/useTouchTrigger';
121
123
  import {themeProps} from '../utils/themeProps';
122
124
  import type {SheetDraftChange} from '../internal/sheetDraft';
123
125
  import type {TokenizerBottomSheetProps} from './TokenizerBottomSheet';
@@ -1102,6 +1104,66 @@ export function Tokenizer<T extends SearchableItem>({
1102
1104
  : {owner: 'content'},
1103
1105
  });
1104
1106
 
1107
+ // Focus a pointer puts on a token's own control stays there: the
1108
+ // person chose that control. The shared tracker says which input moved it.
1109
+ const {ref: modalityRef, readModality} = useInteractionModalityTracking();
1110
+ // The last press that started inside the field. A touch keyboard rises
1111
+ // whenever the field focuses its input during a tap. So a tap on a token's
1112
+ // remove button moves focus to the input only if the input already had it.
1113
+ // `readModality()` tells whether that press is still the latest interaction
1114
+ // in the field's document; a key press since then restores the keyboard
1115
+ // rules.
1116
+ const lastPressRef = useRef<{
1117
+ inputHadFocus: boolean;
1118
+ isFinger: boolean;
1119
+ pressedTokenRemove: Element | null;
1120
+ } | null>(null);
1121
+ // The touch keyboard is down while the input is unfocused. Only a finger's
1122
+ // press counts: a pen's press keeps the default focus rules, as a mouse's
1123
+ // does.
1124
+ const wasKeyboardDown = useCallback(() => {
1125
+ const press = lastPressRef.current;
1126
+ return (
1127
+ press != null &&
1128
+ press.isFinger &&
1129
+ !press.inputHadFocus &&
1130
+ readModality() === 'pointer'
1131
+ );
1132
+ }, [readModality]);
1133
+ // A finger's tap on a token's remove button with the keyboard down keeps
1134
+ // focus out of the field. Chrome focuses a pressed button on the tap's
1135
+ // compatibility mouse events. That focus would expand an `unfocusedInline`
1136
+ // field and remount the control under the finger. Cancelling it, as
1137
+ // InputClearButton does, leaves the field as it was. The stop sees every
1138
+ // press, so a press that turns into a scroll leaves no arm behind.
1139
+ const {onPointerDown: armTapStop, onMouseDown: stopTap} =
1140
+ useTapStop('mousedown');
1141
+ const handlePointerDownCapture = useCallback(
1142
+ (e: React.PointerEvent) => {
1143
+ armTapStop(e);
1144
+ lastPressRef.current = {
1145
+ inputHadFocus:
1146
+ inputRef.current != null &&
1147
+ inputRef.current.ownerDocument.activeElement === inputRef.current,
1148
+ isFinger: e.pointerType === 'touch',
1149
+ pressedTokenRemove: removeControlOf(e.target),
1150
+ };
1151
+ },
1152
+ [armTapStop],
1153
+ );
1154
+ const handleMouseDownCapture = useCallback(
1155
+ (e: React.MouseEvent) => {
1156
+ if (removeControlOf(e.target) != null && wasKeyboardDown()) {
1157
+ stopTap(e);
1158
+ }
1159
+ },
1160
+ [stopTap, wasKeyboardDown],
1161
+ );
1162
+ // The press record ends with its tap: after the click's task, or when the
1163
+ // browser takes the press over for a scroll.
1164
+ const endPress = useCallback(() => {
1165
+ lastPressRef.current = null;
1166
+ }, []);
1105
1167
  // `adaptive` resolves through the policy the selection controls share. An
1106
1168
  // open sheet keeps its presentation until it closes. A resolution change
1107
1169
  // during a task does not replace the open surface.
@@ -1152,9 +1214,6 @@ export function Tokenizer<T extends SearchableItem>({
1152
1214
  // handing focus from one control to the other — so the receiving control
1153
1215
  // does not report it as focus entering from outside.
1154
1216
  const isHandingOffFocusRef = useRef(false);
1155
- // Focus a pointer puts on a token's own control stays there: the
1156
- // person chose that control. The shared tracker says which input moved it.
1157
- const {ref: modalityRef, readModality} = useInteractionModalityTracking();
1158
1217
  // True while the menu returns focus after it closes. That focus stays on
1159
1218
  // the token the menu returns to.
1160
1219
  const isMenuFocusReturnRef = useRef(false);
@@ -1471,7 +1530,9 @@ export function Tokenizer<T extends SearchableItem>({
1471
1530
  // it: it is the keyboard path to its hidden tokens.
1472
1531
  // In a grouped row, a move to the input also scrolls the strip to its
1473
1532
  // end before the press releases, so a press on a token's remove
1474
- // button keeps its focus too.
1533
+ // button keeps its focus too. A finger's tap on a remove button with
1534
+ // the keyboard down keeps focus out of the input. Focusing it would
1535
+ // raise the keyboard for a removal.
1475
1536
  if (
1476
1537
  e.target !== inputRef.current &&
1477
1538
  e.target !== trackRef.current &&
@@ -1481,7 +1542,8 @@ export function Tokenizer<T extends SearchableItem>({
1481
1542
  (e.target instanceof Node &&
1482
1543
  trackRef.current?.contains(e.target) === true))
1483
1544
  ) &&
1484
- !isMenuFocusReturnRef.current
1545
+ !isMenuFocusReturnRef.current &&
1546
+ !(removeControlOf(e.target) != null && wasKeyboardDown())
1485
1547
  ) {
1486
1548
  inputRef.current?.focus();
1487
1549
  }
@@ -1494,6 +1556,7 @@ export function Tokenizer<T extends SearchableItem>({
1494
1556
  onFocus,
1495
1557
  readModality,
1496
1558
  findTokenControl,
1559
+ wasKeyboardDown,
1497
1560
  ],
1498
1561
  );
1499
1562
 
@@ -1693,10 +1756,31 @@ export function Tokenizer<T extends SearchableItem>({
1693
1756
  if (!options?.silent) {
1694
1757
  announce(t('@astryx.tokenizer.tokenRemoved', {label: item.label}));
1695
1758
  }
1696
- inputRef.current?.focus();
1759
+ // Focusing the input inside a keyboard-down tap would raise the
1760
+ // keyboard. The sheet's own removals (`silent`) leave focus to the
1761
+ // sheet.
1762
+ const pressed =
1763
+ !options?.silent && wasKeyboardDown()
1764
+ ? (lastPressRef.current?.pressedTokenRemove ?? null)
1765
+ : null;
1766
+ if (pressed == null) {
1767
+ inputRef.current?.focus();
1768
+ return true;
1769
+ }
1770
+ // A token that held focus, on its remove button or on another of its
1771
+ // controls, unmounts with focus inside it. Focus then moves to the
1772
+ // input, as for every other removal. Focus anywhere else stays where it
1773
+ // is. A built-in token's only control is its remove button.
1774
+ const active = pressed.ownerDocument.activeElement;
1775
+ const token =
1776
+ [...tokenSlotsRef.current].find(slot => slot.contains(pressed)) ??
1777
+ pressed;
1778
+ if (active != null && token.contains(active)) {
1779
+ inputRef.current?.focus();
1780
+ }
1697
1781
  return true;
1698
1782
  },
1699
- [value, onChange, isDisabled, canRemoveItem, announce, t],
1783
+ [value, onChange, isDisabled, canRemoveItem, announce, t, wasKeyboardDown],
1700
1784
  );
1701
1785
 
1702
1786
  // A composing component that words its own Clear all (PowerSearch) provides
@@ -1839,6 +1923,8 @@ export function Tokenizer<T extends SearchableItem>({
1839
1923
  role="group"
1840
1924
  aria-label={label}
1841
1925
  onClick={handleWrapperClick}
1926
+ onPointerDownCapture={handlePointerDownCapture}
1927
+ onMouseDownCapture={handleMouseDownCapture}
1842
1928
  // The control a click activates is recorded while the click passes
1843
1929
  // down through the field, before the token's own handler runs. The
1844
1930
  // record ends with the click's task, also when the token's handler
@@ -1853,7 +1939,16 @@ export function Tokenizer<T extends SearchableItem>({
1853
1939
  }
1854
1940
  }, 0);
1855
1941
  }
1942
+ const press = lastPressRef.current;
1943
+ if (press != null) {
1944
+ setTimeout(() => {
1945
+ if (lastPressRef.current === press) {
1946
+ endPress();
1947
+ }
1948
+ }, 0);
1949
+ }
1856
1950
  }}
1951
+ onPointerCancelCapture={endPress}
1857
1952
  onFocusCapture={handleFocusCapture}
1858
1953
  onBlurCapture={handleBlurCapture}
1859
1954
  // Keys on the field's other controls (clear button, tokens) reach a