An open source design system that's fully customizable and agent ready
TypeScript
fix(Wheel): a two-finger pinch over a picker wheel zooms the page (#8130)
Christopher Chedeau1c38f0a98ad5
diff --git a/.changeset/wheel-pinch-zoom.md b/.changeset/wheel-pinch-zoom.mdnew file mode 100644index 0000000000..459f1380e2--- /dev/null+++ b/.changeset/wheel-pinch-zoom.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] A two-finger pinch over an open picker wheel zooms the page again. The wheels in the TimeInput, DateTimeInput and DateInput bottom sheets accepted vertical pans only, which also refused the browser's pinch-zoom, so the page could not be zoomed over an open picker. They now leave the pinch to the page, as the menus and listboxes already do. Scrolling a wheel is unchanged.++@vjeuxdiff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 681682dae9..292228278f 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -1575,6 +1575,17 @@ jobs:--project chromium \--output menu-press-shadow-root-output+ # A two-finger pinch over an open picker wheel must zoom the page (WCAG+ # 1.4.4) while one finger still scrolls the wheel. jsdom computes no+ # touch-action, so only a real engine shows which gesture the browser+ # keeps.+ - name: Run picker wheel pinch-zoom contract+ run: |+ pnpm exec playwright test \+ packages/core/src/DateInput/__tests__/WheelPinchZoom.a11y.chromium.spec.ts \+ --project chromium \+ --output wheel-pinch-zoom-output+# A sub-menu with a header or footer is a modal dialog beside the root's# menu, outside every role="menu" element. Its Tab order, a header radio# group the browser moves focus in after the pointer leaves, thediff --git a/packages/core/src/DateInput/DateInputTouch.test.tsx b/packages/core/src/DateInput/DateInputTouch.test.tsxindex b27ba2af51..b6f139ba9e 100644--- a/packages/core/src/DateInput/DateInputTouch.test.tsx+++ b/packages/core/src/DateInput/DateInputTouch.test.tsx@@ -2540,6 +2540,15 @@ describe('DateInput — scroll CSS (definition-level)', () => {);});+ it('leaves a two-finger pinch to the page over the wheels', () => {+ // `pan-y` alone also refuses the browser's pinch-zoom over the wheel, so+ // the page could not be zoomed over an open picker. The real-engine proof+ // is WheelPinchZoom.a11y.chromium.spec.ts; jsdom computes no touch-action.+ expect(declarations(read('Wheel.tsx'), 'scroller')).toContain(+ "touchAction: 'pan-y pinch-zoom'",+ );+ });+it('guards the scroll-driven falloff behind @supports', () => {const source = read('Wheel.tsx');// Without the guard, a browser that does not understand animation-timelinediff --git a/packages/core/src/DateInput/Wheel.tsx b/packages/core/src/DateInput/Wheel.tsxindex 8da6ef8bf5..059e4dfd6d 100644--- a/packages/core/src/DateInput/Wheel.tsx+++ b/packages/core/src/DateInput/Wheel.tsx@@ -106,7 +106,10 @@ const styles = stylex.create({transformStyle: 'preserve-3d',scrollbarWidth: 'none',outline: 'none',- touchAction: 'pan-y',+ // Vertical pans scroll the wheel; a two-finger pinch stays the page's, so+ // the page can still zoom over an open picker (WCAG 1.4.4), as it does+ // over the menus and listboxes (`module:DropdownMenu/useMenuPress` FR4).+ touchAction: 'pan-y pinch-zoom',},item: {display: 'flex',diff --git a/packages/core/src/DateInput/__tests__/WheelPinchZoom.a11y.chromium.spec.ts b/packages/core/src/DateInput/__tests__/WheelPinchZoom.a11y.chromium.spec.tsnew file mode 100644index 0000000000..c6357324b8--- /dev/null+++ b/packages/core/src/DateInput/__tests__/WheelPinchZoom.a11y.chromium.spec.ts@@ -0,0 +1,158 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file WheelPinchZoom.a11y.chromium.spec.ts+ * @input The built TimeInput bottom-sheet story and real Chromium touch input+ * (CDP) on a phone profile+ * @output Browser evidence that a two-finger pinch over an open picker wheel+ * zooms the page (WCAG 1.4.4) and changes no value+ * @position Real-engine proof for the wheel's `touch-action`; jsdom computes+ * no touch-action. The menus and listboxes have the same proof in+ * MenuPinchZoom.a11y.chromium.spec.ts.+ */++import {+ expect,+ test,+ type CDPSession,+ type Locator,+ type Page,+} from '@playwright/test';+import {+ DEFAULT_STORYBOOK_DIR,+ serveStorybook,+ type StaticServer,+} from '@astryxdesign/a11y-spec/storybook';++let storybook: StaticServer;+test.beforeAll(async () => {+ storybook = await serveStorybook(+ process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR,+ );+});+test.afterAll(async () => {+ await storybook?.close();+});++// A phone: the viewport meta applies and the page can pinch-zoom.+test.use({+ hasTouch: true,+ isMobile: true,+ viewport: {width: 390, height: 844},+ deviceScaleFactor: 3,+});++const sleep = async (ms: number) =>+ new Promise(resolve => setTimeout(resolve, ms));++async function pageScale(page: Page) {+ return page.evaluate(() => window.visualViewport?.scale ?? 1);+}++async function centerOf(locator: Locator) {+ const box = await locator.boundingBox();+ if (box == null) {+ throw new Error('no rendered bounds');+ }+ return {x: box.x + box.width / 2, y: box.y + box.height / 2};+}++type Point = {x: number; y: number};++// Two fingers land one after the other and spread apart sideways, as a person+// pinches. Sideways, because the wheel pans vertically: a vertical spread would+// spend its first stretch scrolling the wheel before the zoom takes over.+async function pinch(cdp: CDPSession, at: Point) {+ const steps = 12;+ const spread = 3;+ const point = (dx: number, k: number, id: number) => ({+ x: at.x + dx * k,+ y: at.y,+ id,+ });+ await cdp.send('Input.dispatchTouchEvent', {+ type: 'touchStart',+ touchPoints: [point(-30, 1, 1)],+ });+ await sleep(30);+ await cdp.send('Input.dispatchTouchEvent', {+ type: 'touchStart',+ touchPoints: [point(-30, 1, 1), point(30, 1, 2)],+ });+ for (let i = 1; i <= steps; i++) {+ await sleep(16);+ const k = 1 + ((spread - 1) * i) / steps;+ await cdp.send('Input.dispatchTouchEvent', {+ type: 'touchMove',+ touchPoints: [point(-30, k, 1), point(30, k, 2)],+ });+ }+ await sleep(16);+ await cdp.send('Input.dispatchTouchEvent', {+ type: 'touchEnd',+ touchPoints: [],+ });+ await sleep(600);+}++test('a pinch over an open picker wheel zooms the page and changes no value', async ({+ page,+}) => {+ await page.goto(+ `${storybook.origin}/iframe.html?id=core-timeinput--styling-parts&viewMode=story`,+ );+ const field = page.locator('[data-parts-row="control-bottom-sheet"] input');+ await expect(field).toBeVisible();+ await field.tap();+ const wheel = page.getByRole('listbox', {name: 'Minute'});+ await expect(wheel).toBeVisible();+ // Let the sheet finish presenting, so the pinch lands on a wheel at rest.+ await sleep(800);+ const valueBefore = await field.inputValue();+ expect(await pageScale(page)).toBe(1);++ const cdp = await page.context().newCDPSession(page);+ await pinch(cdp, await centerOf(wheel));++ expect(await pageScale(page)).toBeGreaterThan(1.2);+ await expect(wheel).toBeVisible();+ expect(await field.inputValue()).toBe(valueBefore);+});++test('one finger dragged up a wheel still scrolls it and leaves the page at scale 1', async ({+ page,+}) => {+ await page.goto(+ `${storybook.origin}/iframe.html?id=core-timeinput--styling-parts&viewMode=story`,+ );+ const field = page.locator('[data-parts-row="control-bottom-sheet"] input');+ await field.tap();+ const wheel = page.getByRole('listbox', {name: 'Minute'});+ await expect(wheel).toBeVisible();+ await sleep(800);+ const scrollTopBefore = await wheel.evaluate(el => el.scrollTop);++ const cdp = await page.context().newCDPSession(page);+ const at = await centerOf(wheel);+ await cdp.send('Input.dispatchTouchEvent', {+ type: 'touchStart',+ touchPoints: [{x: at.x, y: at.y + 60, id: 1}],+ });+ for (let i = 1; i <= 12; i++) {+ await sleep(16);+ await cdp.send('Input.dispatchTouchEvent', {+ type: 'touchMove',+ touchPoints: [{x: at.x, y: at.y + 60 - i * 10, id: 1}],+ });+ }+ await cdp.send('Input.dispatchTouchEvent', {+ type: 'touchEnd',+ touchPoints: [],+ });+ await sleep(600);++ expect(await wheel.evaluate(el => el.scrollTop)).toBeGreaterThan(+ scrollTopBefore + 60,+ );+ expect(await pageScale(page)).toBe(1);+});