You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 1632191
Browse filesBrowse the repository at this point in the historyBrowse files
feat(SegmentedControl): under a finger the selection slides on UIKit's spring
On touch screens the selected surface slides from the old segment to the new
one on the compositor (spring response 0.40 s, damping ratio 0.85, read from
UISegmentedControl on iOS 26.2) and the two titles that change cross-fade
over 200 ms on Core Animation's default curve, for taps, arrow keys and
programmatic changes alike. A proxy copies the selected segment's computed
surface for the slide and hands it back pixel for pixel; a change mid-flight
keeps position and velocity; Reduce Motion drops the travel, as UIKit does.
The proxy sits at z-index -1 in an isolated track, under every segment's
content whatever the engine composites. Values live in
motion/uikit/segmented.ts; the presentation comes from the shared touch
presentation resolver.
[feat] SegmentedControl: on touch screens the selection slides to the new segment on UIKit's spring and the labels cross-fade, whether a tap, an arrow key or a new `value` moved it. The motion runs on the compositor and keeps moving while the main thread is busy; with Reduce Motion the selection moves without travel.
Copy file name to clipboardExpand all lines: apps/storybook/stories/SegmentedControl.stories.tsx
+53Lines changed: 53 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,7 @@ import {
6
6
SegmentedControl,
7
7
SegmentedControlItem,
8
8
}from'@astryxdesign/core/SegmentedControl';
9
+
import{Button}from'@astryxdesign/core/Button';
9
10
import{Card}from'@astryxdesign/core/Card';
10
11
import{Heading}from'@astryxdesign/core/Heading';
11
12
import{Icon}from'@astryxdesign/core/Icon';
@@ -356,3 +357,55 @@ export const PressedState: Story = {
356
357
);
357
358
},
358
359
};
360
+
361
+
constPERIODS=[
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 and the titles cross-fade, whether a finger, a key or the app
371
+
* changed the value. Segments keep their width when the selection moves: each
372
+
* reserves its title's selected width. With a mouse the selection changes in
373
+
* place, as before.
374
+
*/
375
+
exportconstSelectionMotion: Story={
376
+
name: 'Selection motion',
377
+
parameters: {
378
+
docs: {
379
+
description: {
380
+
story:
381
+
'On a touch screen the selection slides between segments on UIKit’s spring and the titles cross-fade, for taps, arrow keys and programmatic changes alike (the button changes the value from outside). Under Reduce Motion the selection moves without travel. Segments never change width when the selection moves.',
Copy file name to clipboardExpand all lines: packages/core/src/SegmentedControl/SegmentedControl.doc.mjs
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -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.',
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. On touch screens the selection slides to the new segment and the labels cross-fade, as on iOS, whether a tap, an arrow key or a new value moved it; with Reduce Motion it moves without travel.',
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.',
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. On touch screens the selection slides to the new segment and the labels cross-fade, as on iOS, whether a tap, an arrow key or a new value moved it; with Reduce Motion it moves without travel.',
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.',
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. On touch screens the selection slides to the new segment and the labels cross-fade, as on iOS, whether a tap, an arrow key or a new value moved it; with Reduce Motion it moves without travel.',
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.'},
// The touch presentation's selection proxy: a copy of the selected
145
+
// segment's surface that springs from the old segment to the new one, then
146
+
// hands the surface back (useSegmentedSelectionMotion). A negative z-index
147
+
// keeps it under every segment's content however the engine composites
148
+
// it: WebKit's overlap test misses segments the moving layer will cover,
149
+
// so DOM order alone let it paint over their titles mid-slide on iOS.
150
+
// Its paint and box are written when a slide starts; at rest it is hidden.
151
+
thumb: {
152
+
position: 'absolute',
153
+
zIndex: -1,
154
+
top: 0,
155
+
// eslint-disable-next-line @astryx/no-physical-properties -- intentional: the proxy is placed by a physical translate measured from client rects (useSegmentedSelectionMotion), in both directions; a logical anchor would start it at the right edge under RTL.
156
+
left: 0,
157
+
boxSizing: 'border-box',
158
+
transformOrigin: '0 0',
159
+
pointerEvents: 'none',
160
+
visibility: 'hidden',
161
+
// It carries a copy of an already resolved surface, forced colors
162
+
// included (Highlight), so the UA must not remap it again.
163
+
forcedColorAdjust: 'none',
164
+
},
130
165
});
131
166
132
167
constsizeStyles=stylex.create({
@@ -176,6 +211,15 @@ export function SegmentedControl({
176
211
...rest
177
212
}: SegmentedControlProps){
178
213
constsize=useSize(sizeProp,'md');
214
+
// UIKit's motion under a finger (the selection slides on a spring and the
215
+
// titles cross-fade), the theme's transitions under a mouse.
0 commit comments