Skip to content

Commit 93d2ed7

Browse files
committed
fix(DateInput, DateTimeInput): the calendar's toggle and selection follow UIDatePicker's timing
The month/year toggle cross-fades on UIKit's 0.25 s ease-in-ease-out (both sheets; DateTimeInput's was instant) and the title chevron turns a quarter turn from the reading direction to down; a tapped day selects with no transition. The values come from the UIKit constants table through DateInput/tokens.stylex.ts, held to it by a test.
1 parent 2631091 commit 93d2ed7

7 files changed

Lines changed: 311 additions & 60 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[fix] The calendar in the DateInput and DateTimeInput bottom sheets now follows the iOS date picker's timing:
6+
7+
- The month/year toggle cross-fades in 0.25 s on iOS's ease-in-out curve. It used to be a theme-speed linear fade in DateInput and instant in DateTimeInput.
8+
- The title's chevron points along the reading direction and turns a quarter turn to point down while the wheels show.
9+
- A tapped day takes its selection at once, with no colour transition.
10+
11+
@vjeux

‎packages/core/src/DateInput/DateInputTouch.test.tsx‎

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import {useState} from 'react';
4242
import type {ISODateString} from '../utils';
4343
import {InputGroup} from '../InputGroup';
4444
import {InternationalizationProvider} from '../i18n';
45-
import {picker} from '../motion/uikit';
45+
import {datePicker, picker, timing} from '../motion/uikit';
4646
import {DateInput} from './DateInput';
4747
import {
4848
toMonthIndex,
@@ -2199,7 +2199,13 @@ describe('DateInput — scroll CSS (definition-level)', () => {
21992199
* The title chevron is the exception and keeps the token: it rotates, and
22002200
* rotation is travel.
22012201
*/
2202-
it('fades linearly, and eases only the thing that travels', () => {
2202+
/**
2203+
* UIDatePicker's month/year toggle: every fade and the chevron's quarter
2204+
* turn on `UIView.animate`'s default ease-in-ease-out, 0.25 s
2205+
* (motion/uikit/datePicker.ts `calendar.monthYearToggle`). StyleX inlines
2206+
* only literals, so the tokens repeat the table; they must stay it.
2207+
*/
2208+
it('fades and turns on UIDatePicker\u2019s toggle clock, from the table', () => {
22032209
const source = read('TouchDateField.tsx');
22042210
const styles = source.slice(
22052211
source.indexOf('const styles = stylex.create('),
@@ -2209,25 +2215,25 @@ describe('DateInput — scroll CSS (definition-level)', () => {
22092215
styles.indexOf(' titleChevronOpen: {'),
22102216
);
22112217
expect(chevron).toContain("transitionProperty: 'transform'");
2212-
expect(chevron).toContain(
2213-
"transitionTimingFunction: easeVars['--ease-standard']",
2218+
expect(chevron).toContain('transitionTimingFunction: SWAP_CURVE');
2219+
// The arrows, the weekday row, Reset, the layer above and the chevron.
2220+
expect(styles.match(/transitionTimingFunction: SWAP_CURVE/g)).toHaveLength(
2221+
5,
22142222
);
2215-
// The chevron is the only eased transition; every fade is linear.
2216-
expect(
2217-
styles.match(/transitionTimingFunction: easeVars\['--ease-standard'\]/g),
2218-
).toHaveLength(1);
2219-
expect(styles.match(/transitionTimingFunction: 'linear'/g)).toHaveLength(4);
2223+
expect(styles).not.toContain("transitionTimingFunction: 'linear'");
2224+
const tokens = read('tokens.stylex.ts');
2225+
const toggle = datePicker.calendar.monthYearToggle;
2226+
expect(tokens).toContain(`duration: '${toggle.fadeMs}ms'`);
2227+
expect(tokens).toContain(
2228+
`curve: 'cubic-bezier(${timing.curves.easeInOut.join(', ')})'`,
2229+
);
2230+
expect(tokens).toContain(`chevronTurn: '${toggle.chevronTurnDegrees}deg'`);
22202231
});
22212232

22222233
/**
22232234
* Everything in the swap runs for the same time, so it reads as one change
2224-
* rather than several. The chevron included — it used to run
2225-
* `--duration-medium` against a 220ms swap and was still turning well after
2226-
* the wheels had settled.
2227-
*
2228-
* A token rather than a literal, so a consumer's motion scale carries: the
2229-
* Storybook theme resolves `--duration-fast` to 125ms, not the default
2230-
* 175ms, and the swap follows it without knowing.
2235+
* rather than several, the chevron included: UIKit's 0.25 s from the UIKit
2236+
* constants table (physics stays the table's, not a theme's motion scale).
22312237
*/
22322238
it('runs the whole swap on one duration', () => {
22332239
const source = read('TouchDateField.tsx');
@@ -2240,7 +2246,33 @@ describe('DateInput — scroll CSS (definition-level)', () => {
22402246
// And no leftover hand-rolled timing beside them.
22412247
expect(styles).not.toContain('PANEL_FADE_MS');
22422248
expect(source).toContain(
2243-
"const SWAP_DURATION = durationVars['--duration-fast']",
2249+
'const SWAP_DURATION = monthYearToggleMotion.duration',
2250+
);
2251+
});
2252+
2253+
it('selects a tapped day at once, as UIDatePicker does', () => {
2254+
// datePicker.calendar.selection.tapAnimates: no animation on a tap.
2255+
const puck = declarations(read('MonthScroller.tsx'), 'puck');
2256+
expect(puck.some(line => line.startsWith('transition'))).toBe(false);
2257+
});
2258+
2259+
it('cross-fades the DateTimeInput sheet\u2019s month/year toggle on the same clock', () => {
2260+
const source = read('../DateTimeInput/TouchDateTimeField.tsx');
2261+
for (const object of [
2262+
'touchDateSurface',
2263+
'touchHeaderActions',
2264+
'touchTitleChevron',
2265+
]) {
2266+
const lines = declarations(source, object);
2267+
expect(lines).toContain(
2268+
'transitionDuration: monthYearToggleMotion.duration',
2269+
);
2270+
expect(lines).toContain(
2271+
'transitionTimingFunction: monthYearToggleMotion.curve',
2272+
);
2273+
}
2274+
expect(declarations(source, 'touchTitleChevronOpen')).toContain(
2275+
'transform: `rotate(${monthYearToggleMotion.chevronTurn})`',
22442276
);
22452277
});
22462278

‎packages/core/src/DateInput/MonthScroller.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ import {
6060
radiusVars,
6161
fontWeightVars,
6262
typeScaleVars,
63-
durationVars,
6463
borderVars,
6564
} from '../theme/tokens.stylex';
6665
import {focusOutlineStyles} from '../utils';
@@ -176,8 +175,9 @@ const styles = stylex.create({
176175
borderStyle: 'solid',
177176
borderColor: 'transparent',
178177
backgroundColor: 'transparent',
179-
transitionProperty: 'background-color, color, border-color',
180-
transitionDuration: durationVars['--duration-fast'],
178+
// No transition: a tapped day takes its style in the frame of the lift
179+
// and the old one loses it, as UIDatePicker's do
180+
// (datePicker.calendar.selection.tapAnimates).
181181
},
182182
puckHoverable: {
183183
// Two guards, for two different failure modes.

‎packages/core/src/DateInput/TouchDateField.tsx‎

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ import {
9292
fontWeightVars,
9393
typeScaleVars,
9494
typographyVars,
95-
durationVars,
96-
easeVars,
9795
} from '../theme/tokens.stylex';
9896
import {useTooltip} from '../Tooltip';
9997
import {VisuallyHidden} from '../VisuallyHidden';
@@ -124,7 +122,11 @@ import {
124122
fromMonthIndex,
125123
monthIndexOf,
126124
} from './monthGeometry';
127-
import {dateInputTouchSizes, dateInputTouchGeometry} from './tokens.stylex';
125+
import {
126+
dateInputTouchSizes,
127+
dateInputTouchGeometry,
128+
monthYearToggleMotion,
129+
} from './tokens.stylex';
128130

129131
/**
130132
* The comfortable minimum tap target on both iOS and Android, honoured by
@@ -133,23 +135,19 @@ import {dateInputTouchSizes, dateInputTouchGeometry} from './tokens.stylex';
133135
const TOUCH_TARGET = dateInputTouchSizes.daySize;
134136

135137
/**
136-
* The whole surface swap, in one leg.
137-
*
138-
* It used to be two: the outgoing surface faded out, then the incoming one
139-
* faded in, 110ms each. The sequencing existed for one reason — the wheels'
140-
* panel was transparent, so overlapping the two put the wheels' translucent
141-
* selection band over the calendar grid and tinted a band-shaped strip of it,
142-
* which read as "the grey area animates differently from the content".
143-
*
144-
* Giving the wheels an opaque background removes the reason. Nothing shows
145-
* through them, so they can simply fade in ON TOP of a calendar that does not
146-
* move at all — no empty middle, no outgoing animation, and one duration
147-
* instead of a wait plus a fade.
138+
* The whole surface swap, in one leg: UIDatePicker's month/year toggle
139+
* (motion/uikit/datePicker.ts `calendar.monthYearToggle`), where the wheels
140+
* fade in as the grid, the weekday row and the chevrons fade out, all at once,
141+
* 0.25 s on UIKit's default ease-in-ease-out, and the title's chevron turns a
142+
* quarter turn on the same clock.
148143
*
149-
* `--duration-fast` rather than a literal now that this is a whole duration
150-
* and not half of one.
144+
* The wheels' panel is opaque, so it can simply fade in ON TOP of a calendar
145+
* that does not move: nothing shows through it, and the arrows and the
146+
* weekday row (above the panel's reach) fade out beneath it on the same
147+
* timing, so the change reads as one motion.
151148
*/
152-
const SWAP_DURATION = durationVars['--duration-fast'];
149+
const SWAP_DURATION = monthYearToggleMotion.duration;
150+
const SWAP_CURVE = monthYearToggleMotion.curve;
153151

154152
const sizeStyles = stylex.create({
155153
sm: {
@@ -271,7 +269,7 @@ const styles = stylex.create({
271269
// blinking out a beat before the grid is covered.
272270
transitionProperty: 'opacity, visibility',
273271
transitionDuration: SWAP_DURATION,
274-
transitionTimingFunction: 'linear',
272+
transitionTimingFunction: SWAP_CURVE,
275273
'@media (prefers-reduced-motion: reduce)': {
276274
transitionDuration: '0.01s',
277275
},
@@ -328,7 +326,7 @@ const styles = stylex.create({
328326
alignItems: 'center',
329327
transitionProperty: 'opacity, visibility',
330328
transitionDuration: SWAP_DURATION,
331-
transitionTimingFunction: 'linear',
329+
transitionTimingFunction: SWAP_CURVE,
332330
'@media (prefers-reduced-motion: reduce)': {
333331
transitionDuration: '0.01s',
334332
},
@@ -384,19 +382,22 @@ const styles = stylex.create({
384382
titleChevron: {
385383
display: 'inline-flex',
386384
flexShrink: 0,
387-
// The one part of the swap that keeps `--ease-standard`, because it is
388-
// the one part that travels: a rotation has a distance to cover, and
389-
// fast-out-slow-in is what that curve is for. Same duration as the
390-
// surface it announces, so the two land together.
385+
// It points along the reading direction while the calendar shows and
386+
// turns a quarter turn to point down while the wheels show, on the
387+
// toggle's own clock.
391388
transitionProperty: 'transform',
392389
transitionDuration: SWAP_DURATION,
393-
transitionTimingFunction: easeVars['--ease-standard'],
390+
transitionTimingFunction: SWAP_CURVE,
394391
'@media (prefers-reduced-motion: reduce)': {
395392
transitionDuration: '0.01s',
396393
},
397394
},
398395
titleChevronOpen: {
399-
transform: 'rotate(180deg)',
396+
transform: `rotate(${monthYearToggleMotion.chevronTurn})`,
397+
},
398+
titleChevronMirror: {
399+
display: 'inline-flex',
400+
flexShrink: 0,
400401
},
401402
weekdays: {
402403
display: 'grid',
@@ -407,7 +408,7 @@ const styles = stylex.create({
407408
// timing rather than clearing on its own.
408409
transitionProperty: 'opacity, visibility',
409410
transitionDuration: SWAP_DURATION,
410-
transitionTimingFunction: 'linear',
411+
transitionTimingFunction: SWAP_CURVE,
411412
'@media (prefers-reduced-motion: reduce)': {
412413
transitionDuration: '0.01s',
413414
},
@@ -509,7 +510,7 @@ const styles = stylex.create({
509510
isolation: 'isolate',
510511
transitionProperty: 'opacity, visibility',
511512
transitionDuration: SWAP_DURATION,
512-
transitionTimingFunction: 'linear',
513+
transitionTimingFunction: SWAP_CURVE,
513514
'@media (prefers-reduced-motion: reduce)': {
514515
transitionDuration: '0.01s',
515516
},
@@ -1006,17 +1007,21 @@ export function TouchDateField({
10061007
focusOutlineStyles.focusVisible,
10071008
)}>
10081009
<span {...stylex.props(styles.titleText)}>{monthYearLabel}</span>
1009-
<Icon
1010-
icon="chevronDown"
1011-
size="sm"
1012-
color="secondary"
1013-
// The transform rides on the Icon itself, not a wrapper span, so
1014-
// the element a theme can target is the element that moves.
1015-
xstyle={[
1016-
styles.titleChevron,
1017-
isWheelOpen && styles.titleChevronOpen,
1018-
]}
1019-
/>
1010+
{/* Mirrored under RTL so it points along the reading direction;
1011+
the turn rides on the Icon itself, so the element a theme can
1012+
target is the element that moves (mirrored, the same turn still
1013+
ends pointing down). */}
1014+
<span {...stylex.props(styles.titleChevronMirror, rtlStyles.mirror)}>
1015+
<Icon
1016+
icon="chevronRight"
1017+
size="sm"
1018+
color="secondary"
1019+
xstyle={[
1020+
styles.titleChevron,
1021+
isWheelOpen && styles.titleChevronOpen,
1022+
]}
1023+
/>
1024+
</span>
10201025
</button>
10211026
{/* Both arrows at the trailing corner, as a pair — and only while the
10221027
calendar is the surface they step. `IconButton` gives them

0 commit comments

Comments
 (0)