Skip to content

Commit ca05d39

Browse files
committed
feat(DateInput, TimeInput, DateTimeInput): the sheets' wheels draw as one picker in the iOS idiom
The month and year wheels of the DateInput sheet and the time wheels of the TimeInput and DateTimeInput sheets sit in a WheelGroup. In the iOS idiom one selection band spans every column, and each column's dimmed rows lean toward the picker's centre, as UIPickerView draws them. Everywhere else the group renders the columns alone, so the sheets keep today's layout; the sheets' own styles are unchanged.
1 parent 1c1e238 commit ca05d39

9 files changed

Lines changed: 244 additions & 99 deletions

File tree

‎.changeset/wheel-group-inputs.md‎

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] On iOS and iPadOS, under a finger, the wheels in the TimeInput, DateTimeInput and DateInput bottom sheets now draw as one picker, as on iOS. One selection band spans every column, and each column's dimmed rows lean toward the picker's centre instead of their own. On Android and with a mouse the sheets are unchanged.
6+
7+
@vjeux

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,17 @@ function weekdayRow(): HTMLElement {
281281
// Which surface, and why
282282
// ---------------------------------------------------------------------------
283283

284+
/**
285+
* WebKit on iOS, the only engine with `-webkit-touch-callout`: with a coarse
286+
* pointer, the iOS idiom (utils/touchPresentation.ts).
287+
*/
288+
function stubIosWebKit(): void {
289+
vi.stubGlobal('CSS', {
290+
supports: (condition: string) =>
291+
condition.includes('-webkit-touch-callout'),
292+
});
293+
}
294+
284295
describe('DateInput — surface selection', () => {
285296
it('hands a touch device to the platform picker by default', () => {
286297
// `nativePicker` defaults to 'touch': the OS draws the picker unless a
@@ -1430,6 +1441,22 @@ describe('DateInput — month/year wheels', () => {
14301441
const ONE_YEAR = {min: '2026-01-01', max: '2026-12-31'} as const;
14311442
const FIVE_YEARS = {min: '2024-01-01', max: '2028-12-31'} as const;
14321443

1444+
it('draws the month and year wheels as one picker, with one band, in the iOS idiom', () => {
1445+
stubIosWebKit();
1446+
renderAndOpen();
1447+
openWheels();
1448+
expect(panel('wheels').querySelectorAll('[data-wheel-band]')).toHaveLength(
1449+
1,
1450+
);
1451+
});
1452+
1453+
it('keeps the scrolling month and year columns, with no shared band, outside the iOS idiom', () => {
1454+
renderAndOpen();
1455+
openWheels();
1456+
expect(panel('wheels').querySelector('[data-wheel-band]')).toBeNull();
1457+
expect(panel('wheels').querySelector('[data-wheel]')).toBeNull();
1458+
});
1459+
14331460
it('the header title opens them, and says so', () => {
14341461
renderAndOpen();
14351462
expect(title()).toHaveAttribute('aria-expanded', 'false');

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

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {DATE_FORMAT_MONTH_ONLY, plainDateFormat} from '../utils';
2929
import {spacingVars} from '../theme/tokens.stylex';
3030
import {dateInputTouchGeometry} from './tokens.stylex';
3131
import {Wheel, type WheelOption} from './Wheel';
32+
import {WheelGroup} from './WheelGroup';
3233
import {fromMonthIndex, toMonthIndex} from './monthGeometry';
3334

3435
const styles = stylex.create({
@@ -124,25 +125,29 @@ export function MonthYearWheels({
124125

125126
return (
126127
<div {...stylex.props(styles.wheels)}>
127-
<Wheel
128-
label={monthLabel}
129-
options={monthOptions}
130-
value={month}
131-
isActive={isActive}
132-
onChange={nextMonth => onChange(toMonthIndex(year, nextMonth))}
133-
/>
134-
<Wheel
135-
label={yearLabel}
136-
options={yearOptions}
137-
value={year}
138-
isActive={isActive}
139-
onChange={nextYear => {
140-
// Jan 31 -> Feb has no equivalent here (months carry no day), but a
141-
// year change can still land outside the range; clamp to it.
142-
const candidate = toMonthIndex(nextYear, month);
143-
onChange(Math.min(Math.max(candidate, minMonthIndex), maxMonthIndex));
144-
}}
145-
/>
128+
<WheelGroup>
129+
<Wheel
130+
label={monthLabel}
131+
options={monthOptions}
132+
value={month}
133+
isActive={isActive}
134+
onChange={nextMonth => onChange(toMonthIndex(year, nextMonth))}
135+
/>
136+
<Wheel
137+
label={yearLabel}
138+
options={yearOptions}
139+
value={year}
140+
isActive={isActive}
141+
onChange={nextYear => {
142+
// Jan 31 -> Feb has no equivalent here (months carry no day), but a
143+
// year change can still land outside the range; clamp to it.
144+
const candidate = toMonthIndex(nextYear, month);
145+
onChange(
146+
Math.min(Math.max(candidate, minMonthIndex), maxMonthIndex),
147+
);
148+
}}
149+
/>
150+
</WheelGroup>
146151
</div>
147152
);
148153
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
* @output Exports WheelGroup — UIPickerView's frame around picker columns: one
99
* selection band across every column, the picker's height, and the one
1010
* vanishing point all columns are drawn towards
11-
* @position Internal component; the frame of picker Wheels drawn side by side
11+
* @position Internal component; wraps the Wheels in MonthYearWheels.tsx,
12+
* TouchTimeField.tsx and TouchDateTimeField.tsx
1213
*
1314
* The frame is iOS's look, so it draws only where the Wheels are
1415
* UIPickerView's columns: in the iOS idiom of the sheet's touch modes

‎packages/core/src/DateInput/__tests__/WheelRest.a11y.chromium.spec.ts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
* @output Browser evidence that a wheel dragged onto a row outside the bounds
88
* comes to rest on the nearest row inside them and commits it, on today's
99
* column (Chromium on Android) and on the iOS column (the iOS idiom,
10-
* emulated); and that today's column under Reduce Motion fades its rows
11-
* without tipping them
10+
* emulated); that the iOS sheet draws its wheels as one picker while
11+
* today's stay separate; and that today's column under Reduce Motion fades
12+
* its rows without tipping them
1213
* @position Real-engine proof for the rest rule: on today's column, native
1314
* scrolling, CSS snapping and the browser's own end-of-scroll signal; on
1415
* the iOS column, real touch input through the gesture system. None of it
@@ -141,6 +142,14 @@ test('under Reduce Motion, the rows fade toward the edges without tipping', asyn
141142
expect(transform).toBe('none');
142143
});
143144

145+
test('the time wheels stay separate scrolling columns, with no shared band', async ({
146+
page,
147+
}) => {
148+
await openHourWheel(page);
149+
await expect(page.locator('[data-wheel-band]')).toHaveCount(0);
150+
await expect(page.locator('[data-wheel]')).toHaveCount(0);
151+
});
152+
144153
test.describe('in the iOS idiom (emulated)', () => {
145154
/** UIPickerView's row pitch. */
146155
const ROW = picker.geometry.rowHeight;
@@ -189,6 +198,14 @@ test.describe('in the iOS idiom (emulated)', () => {
189198
);
190199
});
191200

201+
test('the time wheels draw as one picker, with one band across them', async ({
202+
page,
203+
}) => {
204+
await openHourWheel(page);
205+
await expect(page.locator('[data-wheel]')).toHaveCount(3);
206+
await expect(page.locator('[data-wheel-band]')).toHaveCount(1);
207+
});
208+
192209
test('a wheel dragged below the minimum comes to rest on the minimum', async ({
193210
page,
194211
}) => {

‎packages/core/src/DateTimeInput/DateTimeInputTouch.test.tsx‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,44 @@ afterEach(() => {
189189
vi.unstubAllGlobals();
190190
});
191191

192+
/**
193+
* WebKit on iOS, the only engine with `-webkit-touch-callout`: with a coarse
194+
* pointer, the iOS idiom (utils/touchPresentation.ts).
195+
*/
196+
function stubIosWebKit(): void {
197+
vi.stubGlobal('CSS', {
198+
supports: (condition: string) =>
199+
condition.includes('-webkit-touch-callout'),
200+
});
201+
}
202+
192203
describe('DateTimeInput touch surface', () => {
204+
it('draws the time wheels as one picker, with one band across them, in the iOS idiom', () => {
205+
stubIosWebKit();
206+
withMonthLayout(() => {
207+
const {container} = render(
208+
<DateTimeInput label="Meeting" onChange={() => {}} />,
209+
);
210+
openDateSheet();
211+
switchToTimePanel();
212+
const timePanel = container.querySelector('[data-panel="time"]')!;
213+
expect(timePanel.querySelectorAll('[data-wheel-band]')).toHaveLength(1);
214+
});
215+
});
216+
217+
it('keeps the scrolling time columns, with no shared band, outside the iOS idiom', () => {
218+
withMonthLayout(() => {
219+
const {container} = render(
220+
<DateTimeInput label="Meeting" onChange={() => {}} />,
221+
);
222+
openDateSheet();
223+
switchToTimePanel();
224+
const timePanel = container.querySelector('[data-panel="time"]')!;
225+
expect(timePanel.querySelector('[data-wheel-band]')).toBeNull();
226+
expect(timePanel.querySelector('[data-wheel]')).toBeNull();
227+
});
228+
});
229+
193230
it('uses the bottom-sheet picker on a coarse pointer', () => {
194231
withMonthLayout(() => {
195232
render(<DateTimeInput label="Meeting" onChange={() => {}} />);

‎packages/core/src/DateTimeInput/TouchDateTimeField.tsx‎

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ import {
9898
} from '../DateInput/MonthScroller';
9999
import {MonthYearWheels} from '../DateInput/MonthYearWheels';
100100
import {Wheel, type WheelOption} from '../DateInput/Wheel';
101+
import {WheelGroup} from '../DateInput/WheelGroup';
101102
import {
102103
dateInputTouchGeometry,
103104
dateInputTouchSizes,
@@ -374,10 +375,10 @@ const styles = stylex.create({
374375
},
375376
touchTimeWheels: {
376377
display: 'flex',
378+
alignItems: 'center',
377379
inlineSize: '100%',
378380
minInlineSize: 0,
379381
blockSize: dateInputTouchGeometry.paneBlockSize,
380-
gap: spacingVars['--spacing-2'],
381382
},
382383
touchFooter: {
383384
display: 'flex',
@@ -1238,50 +1239,54 @@ export function TouchDateTimeField({
12381239
activePanel !== 'time' && styles.touchPanelHidden,
12391240
)}>
12401241
<div {...stylex.props(styles.touchTimeWheels)}>
1241-
<Wheel
1242-
label={t('@astryx.dateTimeInput.hourWheel')}
1243-
options={hourOptions}
1244-
value={
1245-
hourFormat === '24h'
1246-
? parsedWheelTime.hour
1247-
: hour12From24(parsedWheelTime.hour)
1248-
}
1249-
isActive={activePanel === 'time'}
1250-
onChange={hour =>
1251-
commitWheelTime(
1252-
hourFormat === '24h'
1253-
? composeWheelTime({hour24: hour})
1254-
: composeWheelTime({hour12: hour}),
1255-
)
1256-
}
1257-
/>
1258-
<Wheel
1259-
label={t('@astryx.dateTimeInput.minuteWheel')}
1260-
options={minuteOptions}
1261-
value={parsedWheelTime.minute}
1262-
isActive={activePanel === 'time'}
1263-
onChange={minute => commitWheelTime(composeWheelTime({minute}))}
1264-
/>
1265-
{hasSeconds && (
1242+
<WheelGroup>
12661243
<Wheel
1267-
label={t('@astryx.dateTimeInput.secondWheel')}
1268-
options={secondOptions}
1269-
value={parsedWheelTime.second}
1244+
label={t('@astryx.dateTimeInput.hourWheel')}
1245+
options={hourOptions}
1246+
value={
1247+
hourFormat === '24h'
1248+
? parsedWheelTime.hour
1249+
: hour12From24(parsedWheelTime.hour)
1250+
}
12701251
isActive={activePanel === 'time'}
1271-
onChange={second => commitWheelTime(composeWheelTime({second}))}
1252+
onChange={hour =>
1253+
commitWheelTime(
1254+
hourFormat === '24h'
1255+
? composeWheelTime({hour24: hour})
1256+
: composeWheelTime({hour12: hour}),
1257+
)
1258+
}
12721259
/>
1273-
)}
1274-
{hourFormat === '12h' && (
12751260
<Wheel
1276-
label={t('@astryx.dateTimeInput.meridiemWheel')}
1277-
options={meridiemOptions}
1278-
value={parsedWheelTime.hour < 12 ? 0 : 1}
1261+
label={t('@astryx.dateTimeInput.minuteWheel')}
1262+
options={minuteOptions}
1263+
value={parsedWheelTime.minute}
12791264
isActive={activePanel === 'time'}
1280-
onChange={meridiem =>
1281-
commitWheelTime(composeWheelTime({meridiem}))
1282-
}
1265+
onChange={minute => commitWheelTime(composeWheelTime({minute}))}
12831266
/>
1284-
)}
1267+
{hasSeconds && (
1268+
<Wheel
1269+
label={t('@astryx.dateTimeInput.secondWheel')}
1270+
options={secondOptions}
1271+
value={parsedWheelTime.second}
1272+
isActive={activePanel === 'time'}
1273+
onChange={second =>
1274+
commitWheelTime(composeWheelTime({second}))
1275+
}
1276+
/>
1277+
)}
1278+
{hourFormat === '12h' && (
1279+
<Wheel
1280+
label={t('@astryx.dateTimeInput.meridiemWheel')}
1281+
options={meridiemOptions}
1282+
value={parsedWheelTime.hour < 12 ? 0 : 1}
1283+
isActive={activePanel === 'time'}
1284+
onChange={meridiem =>
1285+
commitWheelTime(composeWheelTime({meridiem}))
1286+
}
1287+
/>
1288+
)}
1289+
</WheelGroup>
12851290
</div>
12861291
<div {...stylex.props(styles.touchFooter)}>
12871292
<Button

‎packages/core/src/TimeInput/Presentation.test.tsx‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,48 @@ afterEach(() => {
6161
resetDateSegmentProbe();
6262
});
6363

64+
/**
65+
* WebKit on iOS, the only engine with `-webkit-touch-callout`: with a coarse
66+
* pointer, the iOS idiom (utils/touchPresentation.ts).
67+
*/
68+
function stubIosWebKit(): void {
69+
vi.stubGlobal('CSS', {
70+
supports: (condition: string) =>
71+
condition.includes('-webkit-touch-callout'),
72+
});
73+
}
74+
6475
describe('TimeInput presentation', () => {
76+
it('bottom-sheet draws its wheels as one picker, with one band across them, in the iOS idiom', () => {
77+
stubPointer(true);
78+
stubIosWebKit();
79+
render(
80+
<TimeInput
81+
label="Start"
82+
presentation="bottom-sheet"
83+
onChange={() => {}}
84+
/>,
85+
);
86+
fireEvent.click(screen.getByRole('combobox', {name: 'Start'}));
87+
expect(screen.getByRole('listbox', {name: 'Hour'})).toBeInTheDocument();
88+
expect(document.querySelectorAll('[data-wheel-band]')).toHaveLength(1);
89+
});
90+
91+
it('bottom-sheet keeps its scrolling columns, with no shared band, outside the iOS idiom', () => {
92+
stubPointer(true);
93+
render(
94+
<TimeInput
95+
label="Start"
96+
presentation="bottom-sheet"
97+
onChange={() => {}}
98+
/>,
99+
);
100+
fireEvent.click(screen.getByRole('combobox', {name: 'Start'}));
101+
expect(screen.getByRole('listbox', {name: 'Hour'})).toBeInTheDocument();
102+
expect(document.querySelector('[data-wheel-band]')).toBeNull();
103+
expect(document.querySelector('[data-wheel]')).toBeNull();
104+
});
105+
65106
it('text-input renders the typed field on both pointers', () => {
66107
for (const isCoarse of [false, true]) {
67108
stubPointer(isCoarse);

0 commit comments

Comments
 (0)