Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(DateInput): a wheel's turn from a tap, a key or the program plays the settle spring (#9924)

Christopher Chedeau85788840e2c2
diff --git a/.changeset/wheel-turn-spring.md b/.changeset/wheel-turn-spring.md
new file mode 100644
index 0000000000..68904352d8
--- /dev/null
+++ b/.changeset/wheel-turn-spring.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] DateInput: under a finger, a bottom-sheet wheel's turn onto a tapped row, a key's row or a value set from outside now plays the shared settle spring from rest, instead of a fixed 300 ms ease-in-ease-out. The wheel's main interaction is a gesture, so all its motion springs; a flick's coast and a slow release's snap stay as they are.
+
+@vjeux
diff --git a/docs/specs/AST-094-touch-presentations/spec.md b/docs/specs/AST-094-touch-presentations/spec.md
index 378453223d..2329aa5654 100644
--- a/docs/specs/AST-094-touch-presentations/spec.md
+++ b/docs/specs/AST-094-touch-presentations/spec.md
@@ -966,9 +966,7 @@ under a finger, and a mouse follows `module:DropdownMenu/useMenuPress` FR3 and
spring, as it does today; without a touch presentation a click, a key or a
change of value keeps the theme's curve, unchanged. Implementation gap:
ProgressBar's fill still moves linearly for `progress.fillTrackMs` times the
- share of the track moved under a coarse pointer (`component:ProgressBar` FR4);
- and DateInput's sheet wheel turns onto a clamped or a tapped row on its
- measured tap spin, not `springs.settle` (`component:DateInput` FR14).
+ share of the track moved under a coarse pointer (`component:ProgressBar` FR4).
- Under FR45, a swipe row is a gesture component: a close or return that a tap
or Escape starts (`spec:AST-057` FR5, FR7) plays the row's spring from rest,
and a swipe that closes it keeps its measured spring from the release.
@@ -1010,7 +1008,6 @@ Motion that FR45 moves, by component. Each component's record carries its own li
| Lightbox | Controls fade on a tap, a double tap's zoom, the grow from its source | Named measured roles | Springs, `springs.settle` unless the motion table names another role; the controls fade keeps the main spring's pace |
| TreeList | Group slide under a coarse pointer | Measured motion | Theme tokens |
| ProgressBar | Determinate fill on a value change under a coarse pointer | Linear, `progress.fillTrackMs` times the share moved | `--duration-medium` and the theme's easing, every pointer |
-| DateInput | Sheet wheel turning onto a clamped or a tapped row | `picker.tapSpin.durationMs` on `timing.curves.move` | `springs.settle` from rest |
| DateInput | Sheet wheel under a trackpad | Coarse primary pointer only | Wherever the sheet shows |
| Carousel | Paging under a trackpad swipe | Coarse primary pointer only | Every pointer |
| Every tap-component overlay | A touch exit that a tap, a key or an outside press starts | The native counterpart's timing | `--duration-exit` and `--ease-exit`; the exit switches never remove it; a gesture component's such exit, such as a sheet's or the Lightbox's, plays its spring (FR7) |
diff --git a/docs/specs/components/DateInput/DateInput.spec.md b/docs/specs/components/DateInput/DateInput.spec.md
index e8937d53f4..3be5ebdc23 100644
--- a/docs/specs/components/DateInput/DateInput.spec.md
+++ b/docs/specs/components/DateInput/DateInput.spec.md
@@ -177,7 +177,7 @@ Consumer migration instructions belong in consumer docs and release notes.
| FR11 | Clear MUST emit `undefined` through the ordinary change pipeline. The pointer and bottom-sheet surfaces restore field focus using their shipped timing; the native surface MUST NOT reclaim focus because doing so reopens the OS picker. Implementation gap: when the field becomes disabled or busy while its clear control holds focus, the control unmounts and focus falls to the document body; `spec:AST-085/FR4` requires focus to stay or move to a destination this record names. | Current source and focused clear tests; `spec:AST-085/FR4` |
| FR12 | No surface renders native `disabled`. A disabled field MUST stay focusable with `aria-disabled`, block typing, picking, clearing, and opening, describe its disabled reason when one is given, and take disabled paint. While busy (`isLoading` or a pending Action) the pointer and bottom-sheet surfaces expose `aria-disabled` and `aria-busy`, stay focusable, and block new commits; the native surface does the same for `isLoading`, and during a pending Action stays editable so the OS picker remains attached but rejects additional commits until the Action settles. A busy field that is not disabled keeps its ordinary paint and Spinner, shows no hover ring while commits are blocked, and keeps its keyboard focus ring. While disabled or busy, the field ignores Enter and blur and shows no typed rejection. Typed text whose date typing has not reported stays, and the next Enter or blur once the field is editable commits or rejects it; a new `value` replaces it. Text whose date typing already reported through `onChange` gives way to the field's value once the field is editable again, whether or not the change took it; a focused field keeps the text until the next Enter or blur. Caller handlers other than focus and blur MUST NOT run while the field is disabled (`spec:AST-085` FR2). Implementation gap: only a caller `onClick` is skipped while disabled; caller key, paste, and pointer handlers (such as `onKeyDown`, `onKeyUp`, `onPaste`, and `onPointerDown`) still run on every surface, the native field included. | `spec:AST-085/FR1–FR6`; `family:input-fields/FR4–FR6`; `family:buttons/FR4`; current source and focused tests |
| FR13 | A bottom-sheet picker wheel that comes to rest on a disabled row (outside `min`/`max`) MUST continue to the nearest enabled row, a tie going toward the committed row, and select it there. A wheel resting on its committed row MUST NOT select or commit, even when that row is outside the bounds, so opening a bounded sheet never changes an untouched value: a committed value outside the bounds stays, and an empty field stays empty. This holds for every wheel in the DateInput, TimeInput, and DateTimeInput sheets. | DEC-1; UIDatePicker on the iOS 26.2 simulator; current source |
-| FR14 | A shown bottom-sheet picker wheel whose value changes from outside, as when a bound clamps the time after another wheel turned, MUST turn onto the new row rather than jump to it, on `springs.settle` from rest, as a tap, a key or a program turn does: the wheel's main interaction is a gesture (`spec:AST-094` FR45). The internal motion role `picker.tapSpin.durationMs`, UIKit's measured 300 ms, stays as the measured reference. Under a finger, a tapped row commits its value when its turn ends; a keyboard or assistive-technology activation commits at once. Implementation gap: with the touch presentation, a turn onto a row plays `picker.tapSpin.durationMs` on `timing.curves.move`, whatever pointer starts it, not `springs.settle`; without it, the wheel is a scrolling column and a click or key turn plays the browser's smooth scroll. | UIDatePicker on the iOS 26.2 simulator; current source |
+| FR14 | A shown bottom-sheet picker wheel whose value changes from outside, as when a bound clamps the time after another wheel turned, MUST turn onto the new row rather than jump to it, on `springs.settle` from rest, as a tap, a key or a program turn does: the wheel's main interaction is a gesture (`spec:AST-094` FR45). The internal motion role `picker.tapSpin.durationMs`, UIKit's measured 300 ms, stays as the measured reference. Under a finger, a tapped row commits its value when its turn ends; a keyboard or assistive-technology activation commits at once. Implementation gap: without the touch presentation, the wheel is a scrolling column and a click or key turn plays the browser's smooth scroll. | UIDatePicker on the iOS 26.2 simulator; current source |
| FR15 | Wherever the sheet shows, a sheet wheel's pan takes a trackpad's two-finger scroll, as `spec:AST-094` FR43 allows a record to grant: the rows follow the fingers, coast on at the lift with the fingers' last speed, the coast starting from that speed (`spec:AST-094` FR45), and rest on a row by FR13. A mouse-wheel notch turns the wheel one row, as an arrow key does, with no coast. A ctrl-scroll stays the page's zoom (`spec:AST-094` FR43). Implementation gap: a trackpad drives the wheel only under a coarse primary pointer. | `spec:AST-094` FR43; current source |
| FR16 | Enter in the pointer field's text input commits typed text that has not been committed and is then held back, so a form never submits the value from before the commit. With no typed text pending, Enter is not prevented, so a form submits as it does from any text field, except on a disabled or busy field, where Enter does nothing (`spec:AST-085` FR2). |
| FR17 | In a sheet wheel, Arrow, Page, Home and End move through the wheel's enabled values in time order, skipping disabled ones, and stop at the first or last enabled value; a key with no enabled value in its direction commits nothing, under every presentation. On a 12-hour hour wheel, time order follows the full time (12 PM comes before 1 PM), not the column's row order. | Owner decision (cixzhang, 2026-11-02); current source |
@@ -409,7 +409,7 @@ clear-glyph target of its own.
| AR7 | `apps/storybook/rtl-audit/targets.json` DateInput entry; `DateInputTouch.test.tsx` RTL scroll-offset cases | RTL | A changed audit target or RTL offset fails. | `audit:DateInput/rtl` |
| PR2 | `MonthScrollerSettle.test.tsx` cases; `DateInputTouch.test.tsx` "a rest position between two months" cases | Settle and re-snap | A scroller that never settles or corrects mid-gesture fails. Evidence gap: no test asserts listener, frame, and observer cleanup on unmount, drags a month pager, or counts the visible-month reports per half-month (the PR2 gap). | `audit:DateInput/behavior` |
| FR13 | `Wheel.test.tsx`, the wheel every sheet renders: "stopping below the minimum travels on to the minimum and commits it there", "stopping past the maximum travels back to the maximum", "a stop on another disabled row still travels to the bounds", "opening on a value outside the bounds parks on it without travelling or committing", "a drag that comes back to rest on a committed value outside the bounds stays there and commits nothing", "never commits a disabled row, even with nowhere valid to go", and `nearestEnabledIndex` "breaks a tie toward the committed row"; `PickerWheel.test.tsx`, the wheel under a finger: "turns on to the minimum after resting below it, and commits that", "opening on a value outside the bounds commits nothing", "rests back on a committed value outside the bounds and commits nothing"; `WheelRest.a11y.chromium.spec.ts` in the TimeInput sheet: "a wheel dragged below the minimum comes to rest on the minimum", "a wheel dragged onto a row inside the bounds commits that row"; `DateInputTouch.test.tsx` "bounds the year wheel to the reachable range" (rows outside the bounds are disabled). | Below the minimum, above the maximum, on another disabled row; opened on a value outside the bounds and rested back on it after a drag; DateInput, TimeInput, and DateTimeInput sheets | A wheel that returns to its committed row, skips the nearest enabled row, breaks a tie away from the committed row, or commits on opening or on a rest back on its committed row fails. | `audit:DateInput/behavior` |
-| FR14 | `Wheel.test.tsx` "turns onto a value set while it is shown, as a bound clamping the time after another wheel turned"; `WheelRest.a11y.chromium.spec.ts` in the TimeInput sheet: "a meridiem change past the maximum turns the hour wheel onto it, frame by frame"; `PickerWheel.test.tsx`, the wheel under a finger: "turns the wheel onto its row, as a bound clamping the time", "turns on from where the wheel is drawn when the value changes again during that turn", "plays a tapped row’s turn on the tap spin’s motion role", "turns onto a tapped row and commits it on arrival", "commits each arrow key at once, stepping from the row it is heading to", "commits a clicked row at once and never a disabled one". | A bound clamping the value of a shown wheel after another wheel turned, in DateInput, TimeInput, and DateTimeInput sheets; a tapped row, an arrow key and a row click | A wheel that jumps to the new row fails, and so does a tap that commits at the lift, or a key or click that waits for a turn. | `audit:DateInput/behavior` |
+| FR14 | `Wheel.test.tsx` "turns onto a value set while it is shown, as a bound clamping the time after another wheel turned"; `WheelRest.a11y.chromium.spec.ts` in the TimeInput sheet: "a meridiem change past the maximum turns the hour wheel onto it, frame by frame"; `PickerWheel.test.tsx`, the wheel under a finger: "turns the wheel onto its row, as a bound clamping the time", "turns on from where the wheel is drawn when the value changes again during that turn", "turns onto a tapped row and commits it on arrival", "turns onto a tapped row on the settle spring, from rest, and commits it on arrival", "keeps the spring whatever the theme’s duration and easing tokens", "turns onto a key’s row on the same spring", "commits each arrow key at once, stepping from the row it is heading to", "commits a clicked row at once and never a disabled one". | A bound clamping the value of a shown wheel after another wheel turned, in DateInput, TimeInput, and DateTimeInput sheets; a tapped row, an arrow key and a row click | A wheel that jumps to the new row fails, and so does a tap that commits at the lift, or a key or click that waits for a turn. | `audit:DateInput/behavior` |
| FR15 | `WheelPinchZoom.a11y.chromium.spec.ts` "a pinch over an open picker wheel zooms the page and changes no value"; `DateInputTouch.test.tsx` "leaves a two-finger pinch to the page over the wheels". `PickerWheel.test.tsx` "follows a trackpad’s fingers, coasts on at their lift and rests on a row, as a finger’s flick does", "rests on the nearest row after a slow trackpad drag that stops, without coasting", "turns one row for a mouse wheel’s notch, as an arrow key does, with no coast", "turns three rows for three notches, one each", "leaves a ctrl-wheel, a trackpad pinch, to the page"; `Wheel.interaction.browser.spec.ts` "one mouse-wheel notch turns the touch column one row, as an arrow key does; three turn it three" (Chromium) and the trackpad flick and slow stopped drag (WebKit, whose driver sends a trackpad's deltas). | A trackpad scroll and its lift; a slow stopped trackpad drag; one and three mouse-wheel notches; a ctrl-scroll over an open wheel | A trackpad scroll that does not follow, a lift that stops dead or coasts at the browser's rate, a notch that turns more or less than one row or coasts, or a ctrl-scroll that turns the wheel fails. | `audit:DateInput/behavior` |
| FR16 | `DateInput.test.tsx` "Enter submits the form when nothing is typed, and commits typed text without submitting" "Enter on a disabled field does not submit the form" and "Enter on a busy field does not submit the form" | Nothing typed; typed text; disabled; busy (`isLoading`) | An Enter that is prevented with nothing typed, or that submits before typed text commits, fails. | — |
| FR17 | `TimeInput/Presentation.test.tsx`: "at a 12:00–17:00 bound, ArrowDown from 5 PM commits nothing and ArrowDown from 12 PM commits 1 PM, under a finger", "… under a mouse". `Wheel.test.tsx`, the column under a mouse, and `PickerWheel.test.tsx`, the wheel under a finger: "at a 12:00–17:00 bound, moves a key to the next enabled row and stops at the last one", "at a 12:00–17:00 bound on a 12-hour hour wheel, steps in time order: nothing after 5 PM, and 1 PM after 12 PM", "moves a key from a row outside the bounds onto the first enabled row in its direction". | At a 12:00–17:00 bound, ArrowDown from 5 PM commits nothing and ArrowDown from 12 PM commits 1 PM, under a finger and a mouse | A key that commits a disabled value, leaves time order, or strands 12 PM fails. | `audit:DateInput/behavior` |
diff --git a/docs/specs/components/TimeInput/TimeInput.spec.md b/docs/specs/components/TimeInput/TimeInput.spec.md
index 5c47ff1184..abd692cffe 100644
--- a/docs/specs/components/TimeInput/TimeInput.spec.md
+++ b/docs/specs/components/TimeInput/TimeInput.spec.md
@@ -209,7 +209,7 @@ anatomy-theming map.
| FR3–FR5, AR2 | `TimeInput.test.tsx` typing, blur, invalid, stepping, IME, and format cases, including "shows the catalog format hint for the resolved hour format" (24-hour) | 12h, 24h, seconds; invalid and out of range | A commit of an invalid time, a missing alert, or a step during IME fails. Evidence gap: no test asserts the 12-hour format hint, stepping from the current time when empty, or a step that would leave the range. No test steps while a draft is pending. | `audit:TimeInput/behavior` |
| FR6 | `NativeTimeInput.test.tsx` | Coarse default; range; pending Action; clear; clock button | An out-of-range native commit, or a reopened picker after clear, fails. | `audit:TimeInput/behavior` |
| FR7, ORD3, AR4 | `Presentation.test.tsx` sheet cases | Forced and adaptive sheet; disabled | A sheet field that is not inert while disabled fails. Evidence gap: no test opens the sheet by keyboard or asserts the clock button's tab order. No test disables an out-of-range wheel option or clamps a wheel change. | `audit:TimeInput/behavior` |
-| FR7 | `TimeWheels.test.tsx` "turns AM to PM when the hour goes from 11 to 12, turning the AM/PM column", "turns PM back to AM from 12 to 11", "turns PM to AM from 11 PM to 12, midnight", "keeps the half of the day from 1 to 2", "keeps PM from 12 to 1", "keeps PM from 1 back to 12", "keeps PM from 1 forward to 9, a rest that does not pass between 11 and 12", "leaves the hour on its row when the AM/PM column turns"; `timeWheelRules.test.ts` hour-column and `columnsToTurn` cases; `TimeWheelsTouch.test.tsx` "turns AM to PM from 11 to 12 under %s finger" (TimeInput and DateTimeInput, an iPhone and an Android) and "keeps each column on its own under a mouse"; `TimeWheels.interaction.browser.spec.ts` "the AM/PM column follows the hour from 11 to 12 on UIDatePicker’s turn", "with a mouse each column turns on its own: 11 to 12 stays AM" | 12-hour time: 11 to 12 and back, 11 PM to 12, 1 to 2, 12 to 1 and back, 1 to 9; a finger and a mouse | An hour across 11 and 12 that keeps its half of the day, a move between 12 and 1–6 that flips it, a meridiem wheel that jumps instead of turning, or a mouse sheet whose hour moves the meridiem fails. | `audit:TimeInput/behavior` |
+| FR7 | `TimeWheels.test.tsx` "turns AM to PM when the hour goes from 11 to 12, turning the AM/PM column", "turns PM back to AM from 12 to 11", "turns PM to AM from 11 PM to 12, midnight", "keeps the half of the day from 1 to 2", "keeps PM from 12 to 1", "keeps PM from 1 back to 12", "keeps PM from 1 forward to 9, a rest that does not pass between 11 and 12", "leaves the hour on its row when the AM/PM column turns"; `timeWheelRules.test.ts` hour-column and `columnsToTurn` cases; `TimeWheelsTouch.test.tsx` "turns AM to PM from 11 to 12 under %s finger" (TimeInput and DateTimeInput, an iPhone and an Android) and "keeps each column on its own under a mouse"; `TimeWheels.interaction.browser.spec.ts` "the AM/PM column follows the hour from 11 to 12 on a spring, from rest", "with a mouse each column turns on its own: 11 to 12 stays AM" | 12-hour time: 11 to 12 and back, 11 PM to 12, 1 to 2, 12 to 1 and back, 1 to 9; a finger and a mouse | An hour across 11 and 12 that keeps its half of the day, a move between 12 and 1–6 that flips it, a meridiem wheel that jumps instead of turning, or a mouse sheet whose hour moves the meridiem fails. | `audit:TimeInput/behavior` |
| FR8 | `TimeInput.test.tsx` clear cases; `NativeTimeInput.test.tsx` clear case | With value; empty | A clear on an empty field, or no `undefined`, fails. Evidence gap: no test asserts the focus move after clear on either surface, `changeAction` on clear, or a clear or Save press under reduced motion. | `audit:TimeInput/behavior` |
| FR9, AR3 | `TimeInput.test.tsx` disabled suites; `NativeTimeInput.test.tsx` and `Presentation.test.tsx` disabled cases; `InputGroup.test.tsx` disabled-propagation cases | Each surface; with reason; draft in progress | A lost tab stop, a value change, or a caller `onClick` fails. Evidence gap: no test asserts that caller `onKeyDown` and similar handlers still run while disabled (the FR9 gap). | `audit:TimeInput/accessibility` |
| FR10 | `TimeInput.test.tsx` InputGroup suite | Grouped with description and status | A duplicate label, a visible status icon, or a missed announcement fails. Evidence gap: no test groups the sheet surface. | `audit:TimeInput/accessibility` |
diff --git a/packages/core/src/DateInput/PickerWheel.test.tsx b/packages/core/src/DateInput/PickerWheel.test.tsx
index 677e7ce9b1..831578b52a 100644
--- a/packages/core/src/DateInput/PickerWheel.test.tsx
+++ b/packages/core/src/DateInput/PickerWheel.test.tsx
@@ -25,10 +25,10 @@ import {
it,
vi,
} from 'vitest';
-import {motionRole} from '../motion/roles';
-import {picker, timing} from '../motion/uikit';
+import {springs, timing} from '../motion/uikit';
import {fontWeightVars} from '../theme/tokens.stylex';
import {PickerWheel} from './PickerWheel';
+import {bounceCurve, scaleFor} from './wheelPhysics';
import {
WHEEL_ROW_HEIGHT,
type WheelHandle,
@@ -40,6 +40,16 @@ const ROW = WHEEL_ROW_HEIGHT;
/** The column is laid out 216 px tall, its band's centre 108 px down. */
const CENTRE = 108;
+/**
+ * How long a turn of `rows` rows from rest lasts on `springs.settle`, in ms.
+ * A tap, a key or the program starts that motion.
+ */
+function turnMs(rows: number): number {
+ return (
+ bounceCurve(0, 0, rows * ROW, scaleFor(ROW), springs.settle).duration * 1000
+ );
+}
+
/** Hours 0-23 with 09:00-17:00 bounds: 0-8 and 18-23 are disabled. */
const HOURS: WheelOption[] = Array.from({length: 24}, (_, hour) => ({
value: hour,
@@ -341,7 +351,7 @@ describe('PickerWheel — at rest', () => {
);
strips.length = 0;
rerender(wheel(14));
- advance(Math.round(picker.tapSpin.durationMs / 2));
+ advance(Math.round(turnMs(4) / 2));
rerender(wheel(16));
expect(strips).toHaveLength(2);
const [, second] = strips;
@@ -618,22 +628,10 @@ describe('PickerWheel — a finger', () => {
advance(60);
touch('touchend', column, below);
expect(onChange).not.toHaveBeenCalled();
- advance(310);
+ advance(turnMs(1) + 10);
expect(onChange).toHaveBeenCalledWith(11);
});
- it('plays a tapped row’s turn on the tap spin’s motion role', () => {
- const {column} = renderWheel();
- const below = CENTRE + ROW;
- touch('touchstart', column, below);
- advance(60);
- touch('touchend', column, below);
- expect(motionRole('picker.tapSpin.durationMs')).toMatchObject({
- kind: 'duration',
- value: picker.tapSpin.durationMs,
- });
- });
-
it('a finger’s tap turns once: its lift is cancelled, so the browser sends no click', () => {
// spec:AST-094 FR19: the tap recognizer owns a finger's tap, and the
// row's click handler is left to keys, assistive technology and a mouse.
@@ -655,7 +653,7 @@ describe('PickerWheel — a finger', () => {
column.dispatchEvent(lift);
});
expect(lift.defaultPrevented).toBe(true);
- advance(310);
+ advance(turnMs(1) + 10);
expect(onChange).toHaveBeenCalledTimes(1);
expect(onChange).toHaveBeenCalledWith(11);
});
@@ -1044,6 +1042,125 @@ describe('PickerWheel — a scroll wheel and a trackpad', () => {
});
});
+describe('PickerWheel — a turn that a tap, a key or the program starts', () => {
+ /** Each animation the wheel asks of its strip: its places and their times. */
+ let strips: {places: number[]; times: number[]}[];
+
+ beforeEach(() => {
+ strips = [];
+ // jsdom runs no Web Animations: record what the wheel asks of its strip.
+ Element.prototype.animate = vi.fn(function animate(
+ this: Element,
+ keyframes: Keyframe[],
+ options?: KeyframeAnimationOptions,
+ ) {
+ if (this.hasAttribute('data-wheel-strip')) {
+ const span = Number(options?.duration ?? 0);
+ strips.push({
+ places: keyframes.map(frame => {
+ const [, y = '0'] = String(frame.translate ?? '')
+ .trim()
+ .split(/\s+/);
+ return Number.parseFloat(y) || 0;
+ }),
+ times: keyframes.map(frame => (frame.offset ?? 0) * span),
+ });
+ }
+ return {cancel: () => {}} as unknown as Animation;
+ });
+ });
+
+ afterEach(() => {
+ Reflect.deleteProperty(Element.prototype, 'animate');
+ });
+
+ function tap(column: HTMLElement, y: number) {
+ touch('touchstart', column, y);
+ advance(60);
+ touch('touchend', column, y);
+ }
+
+ /** The strip goes from `from` to `to` on `springs.settle`, from rest. */
+ function expectSpring(
+ strip: {places: number[]; times: number[]},
+ from: number,
+ to: number,
+ ) {
+ const spring = bounceCurve(from, 0, to, scaleFor(ROW), springs.settle);
+ expect(strip.places[0]).toBeCloseTo(from, 1);
+ let inside = 0;
+ strip.times.forEach((t, i) => {
+ // The strip draws whole pixels.
+ expect(Math.abs(strip.places[i] - spring.value(t / 1000))).toBeLessThan(
+ 0.5,
+ );
+ if (t > 0 && t < spring.duration * 1000) {
+ inside++;
+ }
+ });
+ expect(inside).toBeGreaterThanOrEqual(4);
+ }
+
+ it('turns onto a tapped row on the settle spring, from rest, and commits it on arrival', () => {
+ const {column, onChange} = renderWheel();
+ tap(column, CENTRE + ROW);
+ expect(strips).toHaveLength(1);
+ expectSpring(strips[0], -10 * ROW, -11 * ROW);
+ advance(turnMs(1) - 10);
+ expect(onChange).not.toHaveBeenCalled();
+ advance(20);
+ expect(onChange).toHaveBeenCalledWith(11);
+ });
+
+ it('keeps the spring whatever the theme’s duration and easing tokens', () => {
+ // The wheel’s main interaction is a gesture, so its turns spring
+ // (spec:AST-094 FR45): the tokens of a tap-first motion do not time it.
+ const {column} = renderWheel();
+ column.style.setProperty('--duration-medium', '0ms');
+ column.style.setProperty('--ease-move', 'linear');
+ tap(column, CENTRE + ROW);
+ expect(strips).toHaveLength(1);
+ expectSpring(strips[0], -10 * ROW, -11 * ROW);
+ });
+
+ it('turns onto a value set from outside on the same spring (component:DateInput FR14)', () => {
+ const {rerender, onChange} = renderWheel();
+ advance(2000);
+ strips.length = 0;
+ rerender(
+ <PickerWheel
+ label="Hour"
+ options={HOURS}
+ value={14}
+ onChange={onChange}
+ />,
+ );
+ expect(strips).toHaveLength(1);
+ expectSpring(strips[0], -10 * ROW, -14 * ROW);
+ });
+
+ it('turns onto a key’s row on the same spring', () => {
+ const {column} = renderWheel();
+ fireEvent.keyDown(column, {key: 'ArrowDown'});
+ expect(strips).toHaveLength(1);
+ expectSpring(strips[0], -10 * ROW, -11 * ROW);
+ });
+
+ it('keeps a fling’s measured coast', () => {
+ const {column} = renderWheel({
+ options: MINUTES,
+ value: 10,
+ label: 'Minute',
+ });
+ drag(column, 180, 60, {steps: 6, interval: 16});
+ expect(strips.length).toBeGreaterThanOrEqual(1);
+ const coast = strips[strips.length - 1];
+ // A coast decelerates over seconds, far past the spring's turn.
+ expect(coast.times.at(-1)).toBeGreaterThan(turnMs(15));
+ advance(4000);
+ });
+});
+
describe('PickerWheel — under reduced motion', () => {
const FADE_MS = timing.reducedMotionCrossFadeMs;
/** Every animation the wheel started, with its keyframes and timing. */
@@ -1175,7 +1292,7 @@ describe('PickerWheel — mechanics for its owners', () => {
arrived = value;
});
});
- advance(310);
+ advance(turnMs(5) + 10);
await act(async () => {});
expect(arrived).toBe(true);
expect(onChange).toHaveBeenCalledWith(15);
@@ -1253,7 +1370,9 @@ describe('PickerWheel — mechanics for its owners', () => {
onChange={onChange}
/>,
);
- advance(250);
+ // Just past the turn's end: a turn the re-render started again would
+ // still be running.
+ advance(turnMs(15) - 100 + 10);
await act(async () => {});
expect(arrived).toBe(true);
});
diff --git a/packages/core/src/DateInput/PickerWheel.tsx b/packages/core/src/DateInput/PickerWheel.tsx
index 1b8fa58340..9e823317ac 100644
--- a/packages/core/src/DateInput/PickerWheel.tsx
+++ b/packages/core/src/DateInput/PickerWheel.tsx
@@ -32,9 +32,9 @@ import {useGestureRecognizer} from '../gestures/useGestureRecognizer';
import {useIsomorphicLayoutEffect} from '../hooks/useIsomorphicLayoutEffect';
import {rubberBandInverse} from '../motion/rubberBand';
import {resolveMotion} from '../motion/resolveMotion';
-import {picker, registerPickerTable} from '../motion/uikit/picker';
+import {picker} from '../motion/uikit/picker';
import {registerScrollTable, scroll} from '../motion/uikit/scroll';
-import {registerTimingTable, timing} from '../motion/uikit/timing';
+import {registerSpringsTable, springs} from '../motion/uikit/springs';
import {
colorVars,
fontWeightVars,
@@ -49,11 +49,11 @@ import {useOwnScrollGesture} from './useOwnScrollGesture';
import {useWheelListbox} from './useWheelListbox';
import {createWheelStrip, type PlayOptions} from './wheelStrip';
import {
+ bounceCurve,
dragOffset,
nearestIndex,
offsetBounds,
planRelease,
- spinCurve,
type WheelCurve,
type WheelLayout,
} from './wheelPhysics';
@@ -158,20 +158,19 @@ const styles = stylex.create({
});
/**
- * The motion tables the wheel resolves internal roles from: the timing curve,
- * the scroll bounce and the picker's tap spin. The picker table registers as
- * its module loads, but the timing and scroll tables do not. Each register is
- * idempotent, so the wheel calls this right before it resolves a role.
+ * The motion tables the wheel resolves its springs from: the scroll bounce
+ * and the shared springs. The spring rows register as their module loads,
+ * but the scroll table does not. Each register is idempotent, so the wheel
+ * calls this right before it resolves a role.
*/
function registerWheelTables(): void {
- registerTimingTable();
registerScrollTable();
- registerPickerTable();
+ registerSpringsTable();
}
/**
- * A turn onto `to` on the picker's tap spin: its duration and its curve, as
- * resolved under `column` when the turn starts.
+ * A turn onto `to` that a tap, a key or the program starts. The wheel's main
+ * interaction is a gesture, so every turn springs.
*/
function turnCurve(
column: Element | null,
@@ -179,11 +178,12 @@ function turnCurve(
to: number,
): WheelCurve {
registerWheelTables();
- return spinCurve(
+ return bounceCurve(
from,
+ 0,
to,
- resolveMotion(column, picker.tapSpin, 'durationMs') / 1000,
- resolveMotion(column, timing.curves.move),
+ UIKIT_SCALE,
+ resolveMotion(column, springs.settle),
);
}
diff --git a/packages/core/src/DateInput/wheelPhysics.test.ts b/packages/core/src/DateInput/wheelPhysics.test.ts
index 256d003da5..00db039742 100644
--- a/packages/core/src/DateInput/wheelPhysics.test.ts
+++ b/packages/core/src/DateInput/wheelPhysics.test.ts
@@ -4,9 +4,10 @@
* @file wheelPhysics.test.ts
* @input wheelPhysics.ts and per-frame offsets recorded from a UIPickerView,
* with the release velocity UIKit handed its delegate
- * @output Proves the Wheel's curves reproduce UIKit's measured picker: the
- * projected target, the coast onto the row, the coast into an end, the
- * snap, the rubber band, the tap spin and the ticks
+ * @output Proves the Wheel's curves reproduce UIKit's measured picker. They
+ * cover the projected target, the coast onto the row, the coast into an
+ * end and the snap. They also cover the rubber band, a turn from rest and
+ * the ticks
* @position Unit coverage for DateInput/wheelPhysics.ts
*
* The recordings are of a 216 pt UIPickerView column of 60 rows, 32 pt each.
@@ -16,17 +17,16 @@
*/
import {describe, expect, it} from 'vitest';
-import {picker} from '../motion/uikit/picker';
-import {timing} from '../motion/uikit/timing';
+import {springs} from '../motion/uikit/springs';
import {
MAX_PLAN_SECONDS,
+ bounceCurve,
coastCurve,
dragOffset,
planRelease,
projectRelease,
reachesRow,
snapCurve,
- spinCurve,
tickTimes,
type WheelLayout,
} from './wheelPhysics';
@@ -326,25 +326,20 @@ describe('past an end', () => {
});
});
-describe('the tap spin', () => {
- it('turns onto the row on Core Animation’s ease-in-ease-out in 0.3 s', () => {
- const curve = spinCurve(
- 0,
- 64,
- picker.tapSpin.durationMs / 1000,
- timing.curves.move,
- );
- expect(curve.duration).toBe(0.3);
- // UIKit, a tap two rows below the band: 6.8, 25.1, 50.2, 75.4 and 93.7 % of
- // the way at 50 ms steps. The recording starts a few ms early.
- const measured = [0.068, 0.251, 0.502, 0.754, 0.937];
- measured.forEach((fraction, i) => {
- expect(
- Math.abs(curve.value((i + 1) * 0.05) / 64 - fraction),
- ).toBeLessThan(0.025);
- });
- expect(curve.value(0.3)).toBe(64);
- expect(curve.velocity(0.15)).toBeGreaterThan(0);
+describe('a turn from rest', () => {
+ it('springs onto the row on the settle spring, from rest, without overshoot', () => {
+ // A tap, a key or the program turns the wheel on `springs.settle`, from
+ // rest.
+ const curve = bounceCurve(0, 0, 64, 1, springs.settle);
+ expect(curve.velocity(0)).toBe(0);
+ expect(curve.value(curve.duration)).toBe(64);
+ let last = 0;
+ for (let t = 0; t <= curve.duration; t += 1 / 120) {
+ const value = curve.value(t);
+ expect(value).toBeGreaterThanOrEqual(last - 1e-9);
+ expect(value).toBeLessThanOrEqual(64 + 1e-9);
+ last = value;
+ }
});
});
diff --git a/packages/core/src/DateInput/wheelPhysics.ts b/packages/core/src/DateInput/wheelPhysics.ts
index 849eb262e7..f8eb387cde 100644
--- a/packages/core/src/DateInput/wheelPhysics.ts
+++ b/packages/core/src/DateInput/wheelPhysics.ts
@@ -4,8 +4,8 @@
* @file wheelPhysics.ts
* @input A wheel's offset and release velocity, its rows, and the UIKit
* picker constants (motion/uikit/picker.ts)
- * @output The curves a picker wheel moves on: the release plan, the tap spin,
- * the rubber band, and the row crossings that tick
+ * @output The curves a picker wheel moves on: the release plan, the turn's
+ * spring, the rubber band, and the row crossings that tick
* @position Pure math of the touch picker wheel (PickerWheel.tsx)
*
* Positions are px, times seconds and velocities px/s. Row k is under the
@@ -14,7 +14,6 @@
* SYNC: When modified, update wheelPhysics.test.ts and PickerWheel.tsx.
*/
-import {cubicBezier} from '../motion/bezier';
import {projectDistance} from '../motion/projection';
import {solveDecay} from '../motion/decay';
import {rubberBand} from '../motion/rubberBand';
@@ -175,8 +174,9 @@ export function coastCurve(
}
/**
- * The bounce spring, from `from` with `velocity`, onto `to`. `bounce` is
- * `scroll.bounce`'s spring as its caller resolves it.
+ * A spring, from `from` with `velocity`, onto `to`, as its caller resolves
+ * it. A return past an end plays `scroll.bounce`, and a turn from rest plays
+ * `springs.settle`.
*/
export function bounceCurve(
from: number,
@@ -318,38 +318,6 @@ export function planRelease(
return {kind: curve.duration > 0 ? 'coast' : 'snap', index, curve};
}
-/**
- * The tap spin onto a row: UIKit's animated setContentOffset, over
- * `duration` seconds on `curve`.
- */
-export function spinCurve(
- from: number,
- to: number,
- duration: number,
- curve: readonly [number, number, number, number],
-): WheelCurve {
- if (from === to || !(duration > 0)) {
- return restCurve(to);
- }
- const ease = cubicBezier(curve);
- const distance = to - from;
- // Velocity from the eased progress's slope, by a central difference.
- const step = 1e-4;
- return {
- duration,
- to,
- value: t => (t >= duration ? to : from + distance * ease(t / duration)),
- velocity: t => {
- if (t >= duration || t < 0) {
- return 0;
- }
- const a = ease(Math.max(0, t / duration - step));
- const b = ease(Math.min(1, t / duration + step));
- return (distance * (b - a)) / (2 * step * duration);
- },
- };
-}
-
/**
* The times (seconds, ascending) at which a row's centre reaches the band's
* centre during `curve`, after `after` and up to `until`. They are thinned so
diff --git a/packages/core/src/DateInput/wheelStrip.test.ts b/packages/core/src/DateInput/wheelStrip.test.ts
index c44e706767..eecb884354 100644
--- a/packages/core/src/DateInput/wheelStrip.test.ts
+++ b/packages/core/src/DateInput/wheelStrip.test.ts
@@ -13,7 +13,7 @@
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
import {createWheelStrip} from './wheelStrip';
-import {spinCurve, type WheelCurve, type WheelLayout} from './wheelPhysics';
+import type {WheelCurve, WheelLayout} from './wheelPhysics';
const haptics = vi.hoisted(() => ({
canVibrate: vi.fn(() => true),
@@ -146,7 +146,7 @@ describe('createWheelStrip', () => {
expect(ticks).toBeGreaterThan(5);
expect(ticks).toBeLessThanOrEqual(13);
haptics.playHaptic.mockClear();
- strip.play(spinCurve(20 * ROW, 23 * ROW, 0.3, [0.42, 0, 0.58, 1]));
+ strip.play(line(20 * ROW, 23 * ROW, 0.3));
vi.advanceTimersByTime(400);
expect(haptics.playHaptic).not.toHaveBeenCalled();
});
diff --git a/packages/core/src/TimeInput/__tests__/TimeWheels.interaction.browser.spec.ts b/packages/core/src/TimeInput/__tests__/TimeWheels.interaction.browser.spec.ts
index 79e3fb7ff2..b96f522365 100644
--- a/packages/core/src/TimeInput/__tests__/TimeWheels.interaction.browser.spec.ts
+++ b/packages/core/src/TimeInput/__tests__/TimeWheels.interaction.browser.spec.ts
@@ -5,10 +5,10 @@
* @input The built "Bottom Sheet Wheels" TimeInput story, real touch input
* and the interaction harness
* @output Interaction proofs for the sheet's time wheels under a finger, in
- * Chromium and WebKit: an hour drag from 11 to 12 turns AM to PM on the
- * AM/PM column's own spin; the turn advances through a blocked main thread;
- * it cross-fades under Reduce Motion; a finger stops it mid-turn. With a
- * mouse, 11 to 12 stays AM.
+ * Chromium and WebKit. An hour drag from 11 to 12 turns AM to PM on the
+ * AM/PM column's own spring. The turn advances through a blocked main
+ * thread. It cross-fades under Reduce Motion, and a finger stops it
+ * mid-turn. With a mouse, 11 to 12 stays AM.
* @position Interaction tests of TimeWheels.tsx, run by
* `pnpm test:interaction`
*/
@@ -41,17 +41,26 @@ import {
type TouchDriver,
type TrackedFrame,
} from '@astryxdesign/interaction-harness';
-import {cubicBezier} from '../../motion/bezier';
-import {picker} from '../../motion/uikit/picker';
-import {timing} from '../../motion/uikit/timing';
+import {bounceCurve, scaleFor} from '../../DateInput/wheelPhysics';
+import {springs} from '../../motion/uikit/springs';
import {WHEEL_ROW_HEIGHT} from '../../DateInput/wheelOptions';
const storybook = withStorybook(test);
-const TURN_MS = picker.tapSpin.durationMs;
-const move = cubicBezier(timing.curves.move);
-/** The column turn's oracle: the wheel's spin, `timing.curves.move` over `picker.tapSpin`. */
-const spin = (t: number) => (t >= TURN_MS ? 1 : move(Math.max(t, 0) / TURN_MS));
+/**
+ * The column turn's oracle: one row on `springs.settle`, from rest. The
+ * wheel's main interaction is a gesture, so a turn the program starts springs.
+ */
+const turn = bounceCurve(
+ 0,
+ 0,
+ WHEEL_ROW_HEIGHT,
+ scaleFor(WHEEL_ROW_HEIGHT),
+ springs.settle,
+);
+const TURN_MS = turn.duration * 1000;
+const spin = (t: number) =>
+ t >= TURN_MS ? 1 : turn.value(Math.max(t, 0) / 1000) / WHEEL_ROW_HEIGHT;
interface OpenWheels {
driver: TouchDriver;
@@ -210,7 +219,7 @@ async function catchTurn(column: Locator): Promise<void> {
);
}
-test('the AM/PM column follows the hour from 11 to 12 on UIDatePicker’s turn', async ({
+test('the AM/PM column follows the hour from 11 to 12 on a spring, from rest', async ({
page,
}) => {
const {driver, hour, meridiem} = await openWheels(
@@ -226,7 +235,7 @@ test('the AM/PM column follows the hour from 11 to 12 on UIDatePicker’s turn',
// The hour commits at rest; the AM/PM column then turns by itself. The
// page catches that turn as it is created (see catchTurn). So the hold
// below finds it, however late a loaded machine's round trips are. A wait
- // from the harness found the 0.3 s turn already ended.
+ // from the harness found the turn already ended.
const caught = catchTurn(meridiem);
await turnHourTo12(driver, hour);
await caught;
@@ -260,7 +269,7 @@ test('the AM/PM column follows the hour from 11 to 12 on UIDatePicker’s turn',
}));
const fit = compareCurve(progress, spin, 0.02);
expect(fit.pass, JSON.stringify(fit.worst)).toBe(true);
- // The held end timer finishes the turn, as it would have at 0.3 s.
+ // The held end timer finishes the turn, as it would have at its end.
await thawTimers(page);
await waitForRest(meridiem);
@@ -352,7 +361,7 @@ test('the AM/PM turn keeps advancing every frame through a blocked main thread',
}, testInfo) => {
test.skip(
browserName === 'webkit',
- "WebKit's screencast clock is not the page's (frames arrive ~100 ms off), so a 0.3 s turn cannot be placed inside the block; Mobile Safari on the iOS simulator is this proof's WebKit evidence",
+ "WebKit's screencast clock is not the page's (frames arrive ~100 ms off), so a turn this short cannot be placed inside the block; Mobile Safari on the iOS simulator is this proof's WebKit evidence",
);
const {driver, hour, meridiem} = await openWheels(
page,
@@ -503,7 +512,7 @@ test('Reduced Motion: the AM/PM column cross-fades onto PM instead of turning',
});
/**
- * A finger lands on the AM/PM column early in its 0.3 s turn. The column stops
+ * A finger lands on the AM/PM column early in its turn. The column stops
* where it was at the touch's time. The lift rests it on the nearer row.
*
* Chromium's injected touches carry the timestamps they are given. The Wheel
@@ -724,7 +733,7 @@ test(
'core-timeinput--bottom-sheet-wheels',
);
// Caught as it is created (catchTurn), so a late harness still films the
- // turn from its start. Held after waitForAnimation instead, the 0.3 s turn
+ // turn from its start. Held after waitForAnimation instead, the turn
// had ended on a loaded machine.
await installTimerGate(page);
const caught = catchTurn(meridiem);
diff --git a/packages/core/src/motion/uikit/picker.ts b/packages/core/src/motion/uikit/picker.ts
index 5ef450013e..8593ed55ce 100644
--- a/packages/core/src/motion/uikit/picker.ts
+++ b/packages/core/src/motion/uikit/picker.ts
@@ -107,10 +107,10 @@ export const picker = {
/**
* Registers the tap spin's duration as an internal motion role,
* `picker.tapSpin.durationMs`. Every other value stays an internal measured
- * constant. The tap spin's curve is the shared role `timing.curves.move`, and
- * the bounce at an end is `scroll.bounce`. A page that plays no picker motion
- * ships no picker registry. The module registers its own table at import (one
- * idempotent in-memory write, no DOM).
+ * constant. The tap spin is the measured reference: the wheel's turns play
+ * `springs.settle`, and its bounce at an end is `scroll.bounce`. A page that
+ * plays no picker motion ships no picker registry. The module registers its
+ * own table at import (one idempotent in-memory write, no DOM).
*/
export function registerPickerTable(): void {
registerMotionTable('picker', picker, {roles: ['tapSpin.durationMs']});