Skip to content

Commit 2407960

Browse files
committed
test(Wheel): the picker wheel's browser proofs and storyboard
Wheel.interaction.browser.spec.ts drives the TimeInput sheet's minute wheel with real touch input, in the iOS idiom (emulateIosWebKit.ts makes Chromium and WebKit answer as WebKit on iOS). In Chromium and WebKit: a flick coasts on UIKit's curve (the release plan of wheelPhysics.ts, fitted to the engine's own release velocity) onto the row it projects and commits on arrival; a finger landing on the coasting wheel stops it where it is, then it eases onto the nearest row; and a storyboard films a flick and its coast, its trace asserted. In Chromium, which replays the script's timestamps: the coast keeps advancing every frame through a main-thread block, and does no Layout or Paint per frame. WebKit's real-time input gives the release its own velocity, so the iOS simulator capture proves the block there. Outside the iOS idiom (Chromium as Android) the same flick scrolls today's column natively onto a row. PickerWheel.test.tsx adds two jsdom cases for paths the audit named: a fling coasts the same under Reduce Motion (UIPickerView ignores it), and each column leans toward the picker centre from where it is laid out, so an RTL row mirrors the lean.
1 parent ca05d39 commit 2407960

3 files changed

Lines changed: 629 additions & 0 deletions

File tree

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+
[chore] Internal: browser proofs for the iOS picker wheel in Chromium and WebKit, in the iOS idiom (emulated). A flick coasts on UIKit's curve onto the row it projects and commits on arrival. A finger landing on a coasting wheel stops it, and it then eases onto the nearest row. A storyboard films a flick and its coast. In Chromium, the coast also keeps advancing every frame while the main thread is blocked, and does no Layout or Paint per frame. Outside the iOS idiom (Chromium as Android), a flick still scrolls today's column natively onto a row.
6+
7+
@vjeux

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

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {act, fireEvent, render, screen} from '@testing-library/react';
1717
import {createRef} from 'react';
1818
import {afterAll, afterEach, beforeAll, describe, expect, it, vi} from 'vitest';
1919
import {PickerWheel} from './PickerWheel';
20+
import {WheelGroup} from './WheelGroup';
2021
import type {WheelHandle, WheelOption, WheelProps} from './wheelOptions';
2122
import {rowTransform} from './wheelDrum';
2223

@@ -460,3 +461,138 @@ describe('PickerWheel — mechanics for its owners', () => {
460461
expect(onChange.mock.calls[0][0]).toBeGreaterThan(15);
461462
});
462463
});
464+
465+
describe('PickerWheel — Reduce Motion and RTL', () => {
466+
it('coasts the same under Reduce Motion, as UIPickerView does', () => {
467+
const previous = Object.getOwnPropertyDescriptor(window, 'matchMedia');
468+
Object.defineProperty(window, 'matchMedia', {
469+
configurable: true,
470+
value: (query: string) => ({
471+
matches: query.includes('prefers-reduced-motion: reduce'),
472+
media: query,
473+
onchange: null,
474+
addEventListener() {},
475+
removeEventListener() {},
476+
addListener() {},
477+
removeListener() {},
478+
dispatchEvent: () => false,
479+
}),
480+
});
481+
try {
482+
const {column, onChange} = renderWheel({
483+
options: MINUTES,
484+
value: 10,
485+
label: 'Minute',
486+
});
487+
drag(column, 180, 60, {steps: 6, interval: 16});
488+
// Still coasting, not jumped to its rest.
489+
advance(200);
490+
expect(onChange).not.toHaveBeenCalled();
491+
advance(4000);
492+
expect(onChange).toHaveBeenCalledTimes(1);
493+
expect(onChange.mock.calls[0][0]).toBeGreaterThan(15);
494+
} finally {
495+
if (previous == null) {
496+
Reflect.deleteProperty(window, 'matchMedia');
497+
} else {
498+
Object.defineProperty(window, 'matchMedia', previous);
499+
}
500+
}
501+
});
502+
503+
it('leans each column toward the picker centre from where it is laid out, so RTL mirrors it', async () => {
504+
// An RTL row of three 123 px columns in a 402 px picker: AM/PM on the
505+
// left, Hour on the right.
506+
const left: Record<string, number> = {'AM/PM': 17, Minute: 140, Hour: 262};
507+
const spy = vi
508+
.spyOn(HTMLElement.prototype, 'getBoundingClientRect')
509+
.mockImplementation(function (this: HTMLElement) {
510+
const label = this.getAttribute('aria-label');
511+
const isGroup =
512+
this.querySelector(':scope > [data-wheel-band]') != null;
513+
const x = label != null && label in left ? left[label] : 0;
514+
const width = label != null && label in left ? 123 : isGroup ? 402 : 0;
515+
return {
516+
x,
517+
y: 0,
518+
left: x,
519+
top: 0,
520+
right: x + width,
521+
bottom: 216,
522+
width,
523+
height: 216,
524+
toJSON() {},
525+
};
526+
});
527+
// Browsers report each observed box once laid out; the wheels place
528+
// their vanishing point from that report, the group's box included.
529+
// The group draws its frame (and hands its box over) only in the iOS
530+
// idiom: a coarse pointer in WebKit on iOS.
531+
vi.stubGlobal('CSS', {
532+
supports: (condition: string) =>
533+
condition.includes('-webkit-touch-callout'),
534+
});
535+
vi.stubGlobal(
536+
'matchMedia',
537+
vi.fn((query: string) => ({
538+
matches: query === '(pointer: coarse)',
539+
media: query,
540+
addEventListener: () => {},
541+
removeEventListener: () => {},
542+
})),
543+
);
544+
const previousObserver = window.ResizeObserver;
545+
window.ResizeObserver = class {
546+
constructor(private readonly callback: ResizeObserverCallback) {}
547+
observe() {
548+
queueMicrotask(() => this.callback([], this));
549+
}
550+
unobserve() {}
551+
disconnect() {}
552+
};
553+
try {
554+
const meridiem: WheelOption[] = [
555+
{value: 0, label: 'AM'},
556+
{value: 1, label: 'PM'},
557+
];
558+
render(
559+
<div dir="rtl">
560+
<WheelGroup>
561+
<PickerWheel
562+
label="Hour"
563+
options={HOURS}
564+
value={10}
565+
onChange={() => {}}
566+
/>
567+
<PickerWheel
568+
label="Minute"
569+
options={MINUTES}
570+
value={0}
571+
onChange={() => {}}
572+
/>
573+
<PickerWheel
574+
label="AM/PM"
575+
options={meridiem}
576+
value={0}
577+
onChange={() => {}}
578+
/>
579+
</WheelGroup>
580+
</div>,
581+
);
582+
await act(async () => {});
583+
const origin = (label: string) =>
584+
screen
585+
.getByRole('listbox', {name: label})
586+
.querySelector<HTMLElement>('[style*="perspective-origin"]')!.style
587+
.perspectiveOrigin;
588+
// The picker centre is 201 px: the left column draws toward its right,
589+
// the right column toward its left.
590+
expect(origin('AM/PM')).toBe('184px 50%');
591+
expect(origin('Hour')).toBe('-61px 50%');
592+
} finally {
593+
spy.mockRestore();
594+
window.ResizeObserver = previousObserver;
595+
vi.unstubAllGlobals();
596+
}
597+
});
598+
});

0 commit comments

Comments
 (0)