Skip to content

Commit fe89a20

Browse files
vjeuxcixzhang
andcommitted
feat(SegmentedControl): the selection slides on every change and drags with any pointer
Under a finger the selection slides between segments on UISegmentedControl's measured spring (the internal role `segmented.selectionSpring`), for taps, arrow keys and programmatic changes alike; under Reduce Motion it cross-fades in place. A press shows the shared pressed overlay and nothing dims. Dragging the selected segment carries the selection with the pointer and commits once, at the lift, on the segment under it; a lift outside the control selects nothing. Under Reduce Motion a drag still follows the pointer, and only the release cross-fades. A mouse or a pen drags the selection the same way, every change slides on the theme's timing, a click included, and a press while focus is in the control no longer selects before the click. useMediaQuery, which SegmentedControl now reads, returns its server default where the window has no matchMedia, instead of throwing. The SegmentedControl record states the slide, the drag, the label color and the commit at the lift (FR9-FR13, PR2), carried over from meta#8596's owner-decided clauses as built. Both SegmentedControl records drop the implementation gaps this closes, and the touch presentation spec names the new motion role. The action-group tracker owns the tap path's click helpers, which SegmentedControl now calls. Combines meta#8094, meta#8127 and meta#8724. Co-authored-by: Cindy Zhang <cindyxz@meta.com>
1 parent 36f8ea1 commit fe89a20

34 files changed

Lines changed: 7032 additions & 84 deletions
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[feat] SegmentedControl: under a finger, on a touch device (a coarse primary pointer), the control tracks the touch. Dragging the selected segment carries the selection along with the finger, and the segment under the finger is chosen when it lets go (`onChange` fires once, at the lift); letting go outside the control selects nothing. While the selection is dragged, the selected label's colour follows it, with a margin around each boundary so a finger resting on one never flickers; label weights change only at the lift, so nothing reflows under the finger. A tap selects through the browser's own click, and a pressed segment shows the shared pressed overlay; nothing lifts or dims. A vertical drag that starts on the control still scrolls the page. A commit the item's `onClick` vetoes sends the selection back at once; one a controlled parent adopts later lands without a bounce. With Reduce Motion the selection still follows the finger, with no chase, and only the lift cross-fades. Keyboard and assistive technology keep the click; no element is added.
6+
7+
@vjeux
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[feat] SegmentedControl: a mouse or a pen drags the selection as a finger does. A drag from the selected segment carries it with the pointer, and the release commits the segment under the pointer (`onChange` fires once, at the release). A release outside the control selects nothing, and a drag that starts on another segment commits where it lifts. Under a mouse or a pen, every change slides the selection on the theme's duration and easing, not UIKit's spring, and a click slides it too. Keyboard and assistive technology keep the click.
6+
7+
@vjeux
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[feat] SegmentedControl: under a finger the selection slides to the new segment on UIKit's spring, whether a tap, an arrow key or a new `value` moved it. The selection indicator is the control's own pseudo-element, so no element is added. The motion runs on the compositor and keeps moving while the main thread is busy. With Reduce Motion nothing travels or scales: the old selection fades out where it is as the new one fades in. The spring is UIKit's measured one, an internal motion role no theme retunes, and no theme value lengthens the Reduce Motion fade. With a mouse or a pen it slides on the theme's duration and easing instead.
6+
@vjeux
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[fix] `useMediaQuery` returns its server default where the window has no `matchMedia`, as in a test DOM, instead of throwing. Components that read it, such as SegmentedControl, now render in such a DOM.
6+
7+
@vjeux

‎apps/storybook/stories/SegmentedControl.stories.tsx‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
SegmentedControl,
77
SegmentedControlItem,
88
} from '@astryxdesign/core/SegmentedControl';
9+
import {Button} from '@astryxdesign/core/Button';
910
import {Card} from '@astryxdesign/core/Card';
1011
import {Heading} from '@astryxdesign/core/Heading';
1112
import {Icon} from '@astryxdesign/core/Icon';
@@ -356,3 +357,54 @@ export const PressedState: Story = {
356357
);
357358
},
358359
};
360+
361+
const PERIODS = [
362+
{value: 'day', label: 'Day'},
363+
{value: 'week', label: 'Week'},
364+
{value: 'month', label: 'Month'},
365+
{value: 'year', label: 'Year to date'},
366+
];
367+
368+
/**
369+
* On a touch screen the selection slides from one segment to the next on
370+
* UIKit's spring, whether a finger, a key or the app changed the value. With a
371+
* mouse or a pen every change, a click included, slides on the theme's
372+
* duration and easing, and a drag carries it as a finger does.
373+
*/
374+
export const SelectionMotion: Story = {
375+
name: 'Selection motion',
376+
parameters: {
377+
docs: {
378+
description: {
379+
story:
380+
'Under a finger the selection slides between segments on UIKit’s spring, for taps, arrow keys and programmatic changes alike (the button changes the value from outside). Drag the selected segment to another one and let go: the segment under the finger is chosen, and letting go outside the control selects nothing. Under Reduce Motion nothing travels: the old selection fades out as the new one fades in. With a mouse or a pen every change, a click included, slides on the theme’s duration and easing, and a drag carries the selection as a finger does.',
381+
},
382+
},
383+
},
384+
render: () => {
385+
const [value, setValue] = useState('day');
386+
const next = () => {
387+
const index = PERIODS.findIndex(period => period.value === value);
388+
setValue(PERIODS[(index + 1) % PERIODS.length].value);
389+
};
390+
return (
391+
<VStack gap={4} width="100%">
392+
<SegmentedControl value={value} onChange={setValue} label="Period">
393+
{PERIODS.map(period => (
394+
<SegmentedControlItem key={period.value} {...period} />
395+
))}
396+
</SegmentedControl>
397+
<SegmentedControl
398+
value={value}
399+
onChange={setValue}
400+
label="Period, filling the row"
401+
layout="fill">
402+
{PERIODS.map(period => (
403+
<SegmentedControlItem key={period.value} {...period} />
404+
))}
405+
</SegmentedControl>
406+
<Button label="Next period" onClick={next} />
407+
</VStack>
408+
);
409+
},
410+
};

‎docs/specs/AST-094-touch-presentations/motion-roles.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Every motion role a registered table lists (`spec:AST-094` FR4, DEC-5): its kind
66

77
| Role | Kind | Default | Named by |
88
| ---------------------------- | -------- | ----------------------------------- | ------------------ |
9+
| `segmented.selectionSpring` | spring | response 0.4 s, damping ratio 0.85 | `spec:AST-094` FR4 |
910
| `springs.contextMenuDismiss` | spring | response 0.35 s, damping ratio 0.85 | `spec:AST-094` FR4 |
1011
| `springs.contextMenuLift` | spring | response 0.32 s, damping ratio 0.8 | `spec:AST-094` FR4 |
1112
| `springs.contextMenuMorph` | spring | response 0.3 s, damping ratio 0.8 | `spec:AST-094` FR4 |

‎docs/specs/AST-094-touch-presentations/spec.md‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ affects_consumer_docs: []
2727

2828
```json
2929
{
30-
"paths": ["packages/core/src/motion/uikit/slider.ts"]
30+
"paths": [
31+
"packages/core/src/motion/uikit/segmented.ts",
32+
"packages/core/src/motion/uikit/slider.ts"
33+
]
3134
}
3235
```
3336

@@ -155,6 +158,7 @@ a measured, sourced difference exists.
155158
| `springs.contextMenuLift` | damping ratio 0.8, response 0.32 s | measured: UIContextMenuInteraction's preview lift, iOS 26.2 simulator, 2026-10-23 |
156159
| `springs.contextMenuDismiss` | damping ratio 0.85, response 0.35 s | measured: UIContextMenuInteraction's dismissal, iOS 26.2 simulator, 2026-10-23 |
157160
| `springs.contextMenuMorph` | damping ratio 0.8, response 0.3 s | measured: UIContextMenuInteraction's menu entrance and preview shadow, iOS 26.2 simulator, 2026-10-23 |
161+
| `segmented.selectionSpring` | response 0.4 s, damping ratio 0.85 | measured: UISegmentedControl's selection slide, iOS 26.2 simulator, 2026-10-23 |
158162
| `timing.stateChangeMs` | 250 ms | measured: Core Animation's implicit transaction, iOS 26.2 simulator, 2026-10-23 |
159163
| `timing.curves.viewChange` | cubic-bezier(0.25, 0.1, 0.25, 1) | Apple: `CAMediaTimingFunctionName.default` |
160164
| `timing.curves.exit` | cubic-bezier(0.42, 0, 1, 1) | measured: UIKit's ease-in, iOS 26.2 simulator, 2026-10-23 |
@@ -212,7 +216,7 @@ a measured, sourced difference exists.
212216
activation stays the browser's click, except that an action a
213217
`family:action-groups` member tracks activates at the lift (FR26), and a toggle
214218
under `spec:AST-020` FR9's slide-off exception (Switch, Checkbox,
215-
CheckboxListItem) may also complete on a lift after the finger slid off. Where the engine hit-tests an element a compositor animation moves at the motion's start (iOS WebKit), a touch on moving content goes to what was drawn under the finger at touch-down, and a tap there (no recognizer claimed it, the browser did not take it, and it stayed within 45 pt) MUST activate it: the browser's own click for that touch is cancelled or swallowed, and that element receives one click, an editable focused first.
219+
CheckboxListItem) may also complete on a lift after the finger slid off; and a drag that carries SegmentedControl's selected surface commits at the lift on the segment nearest the pointer (`component:SegmentedControl` FR13). Where the engine hit-tests an element a compositor animation moves at the motion's start (iOS WebKit), a touch on moving content goes to what was drawn under the finger at touch-down, and a tap there (no recognizer claimed it, the browser did not take it, and it stayed within 45 pt) MUST activate it: the browser's own click for that touch is cancelled or swallowed, and that element receives one click, an editable focused first.
216220
Under a fine pointer a control uses a third profile with no delay: its
217221
press paint starts at once on `pointerdown`, through the same press
218222
controller and release fade as a finger's, in place of CSS `:active`; the

0 commit comments

Comments
 (0)