Skip to content

Commit 68b7c0c

Browse files
committed
fix(DateInput, DateTimeInput): the sheet's calendar pages like UIDatePicker under a finger
Under a finger (a coarse pointer), on iPhone and Android alike, the sheets' calendar is MonthPager, on #8146's usePager: a swipe moves at most one month, chosen at the lift by UIKit's paging rule, and settles on its paging curve; the title follows the drag and the settle, changing at half a month; the arrows step on setContentOffset's 0.3 s sinusoid, a second tap going on to the month after; inside the sheet, a drag steeper than 45 degrees moves the sheet and one flatter than about 27 degrees pages the calendar; a horizontal trackpad swipe pages one month per gesture. With a mouse the calendar keeps today's native scroller, which now takes PageUp/PageDown and follows design:reduced-motion for its arrows (at once with a mouse, an opacity dip on a touch screen, through reducedMotionFade). MonthPager is reached through the pickers' touch layer, DateInput/datePickerTouch.ts.
1 parent e3a210f commit 68b7c0c

13 files changed

Lines changed: 1942 additions & 26 deletions
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[fix] Under a finger, the calendar in the DateInput and DateTimeInput bottom sheets now pages its months like the iOS date picker, on iPhone and Android alike:
6+
7+
- A swipe moves at most one month, chosen at the lift by iOS's paging rule (a quick flick, or past half a month). It settles on iOS's paging curve instead of letting a fling run across several months.
8+
- The month title follows the drag and the settle that ends it. It changes when the next month is more than half in view, not at the lift.
9+
- The arrows scroll the month in 0.3 s; a second tap mid-scroll goes on to the month after.
10+
- Inside the sheet, a drag steeper than 45° moves the sheet, one flatter than about 27° pages the calendar, and one in between moves neither, as on iOS.
11+
- A horizontal trackpad swipe, or Shift with a mouse wheel, pages one month per gesture too.
12+
13+
With a mouse, the calendar keeps today's native scrolling. On every pointer, PageUp and PageDown now move the keyboard focus by a month, and with Shift by a year.
14+
15+
With Reduce Motion on (`design:reduced-motion`), the months no longer travel: under a finger the arrows' step and a swipe's settle cross-fade in 200 ms, and with a mouse the arrows change the month at once.
16+
17+
@vjeux

‎apps/storybook/stories/DateInput.stories.tsx‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,26 @@ export const WithMinMax: Story = {
361361
},
362362
};
363363

364+
/**
365+
* The bottom-sheet calendar pages its months like the iOS date picker: one
366+
* month per swipe, the title following the drag, the arrows on a 0.3 s
367+
* curve.
368+
*/
369+
export const BottomSheetCalendar: Story = {
370+
render: args => {
371+
const [value, setValue] = useState<ISODateString | undefined>(
372+
'2026-10-15' as ISODateString,
373+
);
374+
return <DateInput {...args} value={value} onChange={setValue} />;
375+
},
376+
args: {
377+
label: 'Date',
378+
presentation: 'bottom-sheet',
379+
min: '2026-01-01' as ISODateString,
380+
max: '2026-12-31' as ISODateString,
381+
},
382+
};
383+
364384
export const WithMaxDateInLayout: Story = {
365385
render: args => {
366386
const [value, setValue] = useState<ISODateString | undefined>(undefined);

‎packages/core/src/DateInput/DateInput.spec.md‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,12 @@ approved policy.
186186

187187
- **PR1 — Bounded calendar window.** The bottom-sheet calendar mounts a bounded window
188188
of month panes around the visible month rather than the complete reachable century.
189-
- **PR2 — Scroll work.** Scroll-driven measurement and selection updates remain
190-
animation-frame throttled or settle-driven; listeners, frames, timers, and observers
191-
are cleaned up on deactivation or unmount.
189+
- **PR2 — Scroll and gesture work.** On the native month scroller, scroll-driven
190+
measurement and selection updates remain animation-frame throttled or settle-driven.
191+
On the month pager under a finger, a drag moves the month grid without a render, and the
192+
visible month is reported once per half-month crossed, during the drag and the settle
193+
that ends it.
194+
Listeners, frames, timers, and observers are cleaned up on deactivation or unmount.
192195

193196
## Accessibility contract
194197

@@ -221,8 +224,7 @@ approved policy.
221224
`aria-selected` on the chosen day; ArrowLeft and ArrowRight move by a day
222225
following the reading direction, ArrowUp and ArrowDown by a week, Home and End
223226
to the ends of the week, PageUp and PageDown by a month, and Enter or Space
224-
picks the focused day. Implementation gap: PageUp/PageDown do not page by a
225-
month.
227+
picks the focused day.
226228

227229
## Design relationships
228230

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

Lines changed: 162 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ import {picker} from '../motion/uikit';
5858
import {SWIPE_DISTANCE} from './useOwnScrollGesture';
5959
import {DRAG_SLOP} from './usePointerDragScroll';
6060
import {SCROLL_QUIET_MS} from './useScrollSettle';
61+
import {useCalendarDays} from '../Calendar';
62+
import type * as CalendarModule from '../Calendar';
63+
64+
// A pass-through spy: each call is one month pane rendering, which the
65+
// month/year toggle test counts.
66+
vi.mock('../Calendar', async importOriginal => {
67+
const actual = await importOriginal<typeof CalendarModule>();
68+
return {...actual, useCalendarDays: vi.fn(actual.useCalendarDays)};
69+
});
6170

6271
// ---------------------------------------------------------------------------
6372
// jsdom scaffolding
@@ -139,6 +148,16 @@ function setViewport(kind: 'mobile' | 'desktop'): void {
139148
);
140149
}
141150

151+
/**
152+
* A touchscreen laptop with the sheet pinned (`presentation="bottom-sheet"`):
153+
* the primary pointer is fine, so the calendar is today's native scroller,
154+
* and a finger can still swipe it. Under a primary finger the calendar is
155+
* MonthPager instead.
156+
*/
157+
function stubTouchscreenLaptop(): void {
158+
stubMedia({pointer: 'fine', anyPointer: 'coarse', width: 1280});
159+
}
160+
142161
/**
143162
* Run `fn` with the month scrollport reporting the height its CSS gives it.
144163
*
@@ -858,6 +877,54 @@ describe('DateInput — calendar surface', () => {
858877
expect(header()).toHaveTextContent('March 2026');
859878
});
860879

880+
it('under a finger: names the month at the tap and steps again from it mid-scroll', () => {
881+
renderAndOpen(
882+
<Controlled initial="2026-03-21" min="2026-01-01" max="2026-12-31" />,
883+
);
884+
const header = () =>
885+
document.querySelector<HTMLElement>('[data-title="month-year"]')!;
886+
fireEvent.click(screen.getByRole('button', {name: 'Next month'}));
887+
expect(header()).toHaveTextContent('April 2026');
888+
fireEvent.click(screen.getByRole('button', {name: 'Next month'}));
889+
expect(header()).toHaveTextContent('May 2026');
890+
// The window follows the target, so May's pane is mounted already.
891+
expect(pane('May 2026')).toBeInTheDocument();
892+
});
893+
894+
it('pages the keyboard focus by month with PageUp/PageDown and by year with Shift, on every pointer', () => {
895+
renderAndOpen(
896+
<Controlled initial="2026-03-21" min="2025-01-01" max="2026-12-31" />,
897+
);
898+
const day = within(pane('March 2026')).getByRole('button', {
899+
name: /March 21, 2026/,
900+
});
901+
day.focus();
902+
// Today's scroller follows the focus with a native smooth scroll, which
903+
// jsdom does not run; the focus itself is what moves on every pointer.
904+
fireEvent.keyDown(day, {key: 'PageDown'});
905+
expect(document.activeElement).toHaveAttribute('data-date', '2026-04-21');
906+
fireEvent.keyDown(document.activeElement!, {key: 'PageUp', shiftKey: true});
907+
expect(document.activeElement).toHaveAttribute('data-date', '2025-04-21');
908+
});
909+
910+
it('under a finger: pages the keyboard focus by month with PageUp/PageDown and by year with Shift', () => {
911+
renderAndOpen(
912+
<Controlled initial="2026-03-21" min="2025-01-01" max="2026-12-31" />,
913+
);
914+
const header = () =>
915+
document.querySelector<HTMLElement>('[data-title="month-year"]')!;
916+
const day = within(pane('March 2026')).getByRole('button', {
917+
name: /March 21, 2026/,
918+
});
919+
day.focus();
920+
fireEvent.keyDown(day, {key: 'PageDown'});
921+
expect(document.activeElement).toHaveAttribute('data-date', '2026-04-21');
922+
expect(header()).toHaveTextContent('April 2026');
923+
fireEvent.keyDown(document.activeElement!, {key: 'PageUp', shiftKey: true});
924+
expect(document.activeElement).toHaveAttribute('data-date', '2025-04-21');
925+
expect(header()).toHaveTextContent('April 2025');
926+
});
927+
861928
/**
862929
* A programmatic scroll must not report its own arrival as if the user had
863930
* scrolled there. Nothing needs the report — whatever asked for the scroll
@@ -870,9 +937,15 @@ describe('DateInput — calendar surface', () => {
870937
* again — so the month drifted on the way back to the calendar.
871938
*/
872939
it('does not report a scroll it was told to make', async () => {
940+
stubTouchscreenLaptop();
873941
await withLayout(async () => {
874942
render(
875-
<Controlled initial="2026-03-21" min="2026-01-01" max="2026-12-31" />,
943+
<Controlled
944+
initial="2026-03-21"
945+
min="2026-01-01"
946+
max="2026-12-31"
947+
presentation="bottom-sheet"
948+
/>,
876949
);
877950
fireEvent.click(field());
878951
const header = () =>
@@ -1269,8 +1342,17 @@ describe('DateInput — a rest position between two months', () => {
12691342
scroller.dispatchEvent(touchEvent('touchend'));
12701343
};
12711344

1345+
// Rest positions between two months are the native scroller's; under a
1346+
// primary finger the calendar is MonthPager, which rests only on a month.
12721347
const openCalendar = () => {
1273-
render(<Controlled initial="2026-03-21" {...FIVE_YEARS} />);
1348+
stubTouchscreenLaptop();
1349+
render(
1350+
<Controlled
1351+
initial="2026-03-21"
1352+
{...FIVE_YEARS}
1353+
presentation="bottom-sheet"
1354+
/>,
1355+
);
12741356
fireEvent.click(screen.getByLabelText('Event date'));
12751357
const scroller = document.querySelector<HTMLElement>(
12761358
'[data-scroller="months"]',
@@ -1506,6 +1588,23 @@ describe('DateInput — month/year wheels', () => {
15061588
expect(title()).toHaveTextContent('September 2026');
15071589
});
15081590

1591+
it('under a finger: moves the hidden calendar to the wheels\u2019 month without an echo', () => {
1592+
withLayout(() => {
1593+
render(<Controlled initial="2026-03-21" {...FIVE_YEARS} />);
1594+
fireEvent.click(field());
1595+
openWheels();
1596+
fireEvent.click(
1597+
within(screen.getByRole('listbox', {name: 'Month'})).getByText(
1598+
'January',
1599+
),
1600+
);
1601+
expect(title()).toHaveTextContent('January 2026');
1602+
fireEvent.click(title());
1603+
expect(title()).toHaveTextContent('January 2026');
1604+
expect(pane('January 2026')).toBeInTheDocument();
1605+
});
1606+
});
1607+
15091608
/**
15101609
* A wheel commit steers the hidden calendar, and the calendar reports the
15111610
* month it lands on. Taking that report back while the wheels are open
@@ -1566,8 +1665,15 @@ describe('DateInput — month/year wheels', () => {
15661665
* which is what the re-snap amounts to.
15671666
*/
15681667
it('holds the month when the hidden calendar is re-snapped on reveal', async () => {
1668+
stubTouchscreenLaptop();
15691669
await withLayout(async () => {
1570-
render(<Controlled initial="2026-03-21" {...FIVE_YEARS} />);
1670+
render(
1671+
<Controlled
1672+
initial="2026-03-21"
1673+
{...FIVE_YEARS}
1674+
presentation="bottom-sheet"
1675+
/>,
1676+
);
15711677
fireEvent.click(field());
15721678
openWheels();
15731679
fireEvent.click(
@@ -2024,10 +2130,33 @@ describe('DateInput — nested scrollers keep their own touch gesture', () => {
20242130
ancestor.stop();
20252131
});
20262132

2027-
it('keeps a diagonal drag, because a thumb arcs as it swipes', () => {
2133+
it('under a finger: keeps a drag up to 45° from the sheet', () => {
2134+
renderAndOpen();
2135+
const scroller = document.querySelector('[data-scroller="months"]')!;
2136+
const ancestor = watchAncestor();
2137+
// ~42° off horizontal.
2138+
swipe(scroller, -80, 72);
2139+
expect(ancestor.seen).not.toContain('touchmove');
2140+
ancestor.stop();
2141+
});
2142+
2143+
it('under a finger: gives a drag steeper than 45° to the sheet', () => {
20282144
renderAndOpen();
20292145
const scroller = document.querySelector('[data-scroller="months"]')!;
20302146
const ancestor = watchAncestor();
2147+
// ~50° off horizontal.
2148+
swipe(scroller, -60, 72);
2149+
expect(ancestor.seen).toContain('touchmove');
2150+
ancestor.stop();
2151+
});
2152+
2153+
it('keeps a diagonal drag, because a thumb arcs as it swipes', () => {
2154+
stubTouchscreenLaptop();
2155+
renderAndOpen(
2156+
<Controlled initial="2026-03-21" presentation="bottom-sheet" />,
2157+
);
2158+
const scroller = document.querySelector('[data-scroller="months"]')!;
2159+
const ancestor = watchAncestor();
20312160
// ~50° off horizontal: past the browser's own pan-x cone, still ours.
20322161
swipe(scroller, -60, 72);
20332162
expect(ancestor.seen).not.toContain('touchmove');
@@ -2041,7 +2170,10 @@ describe('DateInput — nested scrollers keep their own touch gesture', () => {
20412170
* from 45° to 60° on an iPhone 15 profile.
20422171
*/
20432172
it('pages a month itself when the browser refuses to pan a claimed swipe', () => {
2044-
renderAndOpen();
2173+
stubTouchscreenLaptop();
2174+
renderAndOpen(
2175+
<Controlled initial="2026-03-21" presentation="bottom-sheet" />,
2176+
);
20452177
const scroller = document.querySelector('[data-scroller="months"]')!;
20462178

20472179
const forward = swipe(scroller, -60, 72);
@@ -2444,6 +2576,31 @@ describe('DateInput — scroll CSS (definition-level)', () => {
24442576
).toHaveLength(2);
24452577
});
24462578

2579+
it('under a finger: the month/year toggle leaves the calendar\u2019s days alone', () => {
2580+
// The toggle re-renders the sheet; nothing the calendar shows changes, so
2581+
// no month pane may re-render (each formats 42 day labels, which was most
2582+
// of the toggle's main-thread work on a phone).
2583+
renderAndOpen();
2584+
vi.mocked(useCalendarDays).mockClear();
2585+
fireEvent.click(document.querySelector('[data-title="month-year"]')!);
2586+
expect(vi.mocked(useCalendarDays)).not.toHaveBeenCalled();
2587+
});
2588+
2589+
it('under a finger: MonthPager pages the months with the shared pager, each pane on its own layer', () => {
2590+
const source = read('MonthPager.tsx');
2591+
// UIKit's paging scroll view, not native scroll snapping: iOS gives a
2592+
// snapping scroller the fast rate bent onto WebKit's own target.
2593+
expect(source).toContain('usePager(');
2594+
expect(source).not.toContain('scrollSnapType');
2595+
// Mobile Safari paints a layer whole before it moves.
2596+
expect(source).toContain("willChange: 'transform'");
2597+
// The pane and the viewport must come from the same expression, or a
2598+
// pane stops being exactly one screen.
2599+
expect(
2600+
source.match(/blockSize: dateInputTouchGeometry\.paneBlockSize/g),
2601+
).toHaveLength(2);
2602+
});
2603+
24472604
it('positions panes with logical properties, so RTL mirrors', () => {
24482605
const source = read('MonthScroller.tsx');
24492606
// Scoped to the style objects: `scrollTo({left})` is the DOM API and is

0 commit comments

Comments
 (0)