From e0aaa628d564dd79f9223185d714f1452c50cbb2 Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Sun, 15 Nov 2026 01:30:19 -0500 Subject: [PATCH 1/2] A finger's tap on a control in a sheet a field's focus raised reaches the control --- host/web/navigation/routes.js | 17 +++++++++++++++++ host/web/tests/sheet-detent.test.mjs | 17 ++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/host/web/navigation/routes.js b/host/web/navigation/routes.js index 3772efe6f..dde4ac3ca 100644 --- a/host/web/navigation/routes.js +++ b/host/web/navigation/routes.js @@ -131,6 +131,9 @@ const WIDE_WIDTH = 900, WIDE = `(min-width: ${WIDE_WIDTH}px)`, wide = () => { let splitLists = new WeakMap(), rowOf = new WeakMap(), actionRows = new WeakMap(), visits = new Map(); const activationRequired = new WeakSet(), activated = new WeakSet(); const sheet = (route) => ["modal", "fullscreen"].includes(route?.getAttribute("navigationPresentation")); +// The fields whose focus raises a narrow sheet on a touch screen, and where it does (neutral.css). +const FIELD = 'textarea, input:not([type="checkbox"], [type="radio"], [type="range"], [type="button"], [type="submit"], [type="reset"], [type="color"], [type="file"], [type="image"]), [contenteditable]:not([contenteditable="false"])'; +const RAISES = "(width < 900px) and (min-height: 480px) and (any-pointer: coarse)"; // A sheet's frame (`sheetFrame`, below), which the projection writes once a host hands it over: the wasm host's glue // for every plan, the JS target's compiler only for a plan that can present a sheet (LLP 1047.002 D1). A plan that // cannot has no route in a sheet, so there is nothing to write. @@ -832,6 +835,20 @@ export const navigation = { hostGo = goTo; routeMatches = matchesRoute; canonicalOf = canonical; + // On a touch screen a field with the focus raises its narrow sheet to the tallest (neutral.css, as the keyboard does + // on iOS). A finger's tap on a control in that sheet leaves the focus in the field, as a UIKit control leaves the + // first responder: a mousedown's focus would blur the field and drop the sheet to its detent before the click, + // which would then land beside the control. + let finger = false; + addEventListener("pointerdown", (e) => { + finger = e.pointerType === "touch"; + }, { capture: true, passive: true }); + addEventListener("mousedown", (e) => { + const field = document.activeElement, raised = field?.closest?.("[data-exact-detent]"); + if (finger && raised?.contains(e.target) && field.matches(FIELD) && !e.target.closest?.(`${FIELD}, select, label`) && globalThis.matchMedia?.(RAISES).matches) { + e.preventDefault(); + } + }, true); for (const type of [ "wheel", "touchmove", diff --git a/host/web/tests/sheet-detent.test.mjs b/host/web/tests/sheet-detent.test.mjs index f748e16dd..0416bffd6 100644 --- a/host/web/tests/sheet-detent.test.mjs +++ b/host/web/tests/sheet-detent.test.mjs @@ -26,7 +26,7 @@ const abs = 'position:absolute;inset:0;display:flex;flex-direction:column'; const page = '' + style + `

Home

Sheet

-

Pushed

+

Pushed

Over

Full

Top

@@ -43,6 +43,8 @@ const page = ' inChrome(async (evaluate, size, call) => { + // The case this guards: a route pushed inside a sheet whose field has the focus (an autofocused one). + expect(await open(evaluate, 'medium large')).toEqual([428, 416]); + await call('Emulation.setTouchEmulationEnabled', { enabled: true, maxTouchPoints: 1 }); + await size(390, 844); + expect(await evaluate(`select('3'); document.getElementById('pushedField').focus(); box('pushed')`)).toEqual([12, 832]); + const [x, y] = await evaluate(`(b => [b.x + b.width / 2, b.y + b.height / 2])(document.getElementById('pushedGo').getBoundingClientRect())`); + await call('Input.dispatchTouchEvent', { type: 'touchStart', touchPoints: [{ x, y }] }); + await call('Input.dispatchTouchEvent', { type: 'touchEnd', touchPoints: [] }); + expect(await evaluate(`new Promise(r => setTimeout(r, 300)).then(() => [clicks.splice(0), document.activeElement.id, box('pushed')])`)) + .toEqual([['pushedGo'], 'pushedField', [12, 832]]); +}), 60000); + check('a bound value keeps the detents UIKit keeps: a word it cannot read or one out of order is dropped', () => inChrome(async (evaluate) => { expect(await open(evaluate, '0% large')).toEqual([12, 832]); expect(await open(evaluate, 'tall 300 large')).toEqual([544, 300]); From 2861a8b950ee8224034cb4467d17568ac76e07c8 Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Sun, 15 Nov 2026 01:39:00 -0500 Subject: [PATCH 2/2] A mouse's press on a touch screen keeps a raised sheet raised too --- host/web/navigation/routes.js | 12 ++++-------- host/web/tests/sheet-detent.test.mjs | 9 ++++++--- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/host/web/navigation/routes.js b/host/web/navigation/routes.js index dde4ac3ca..62a2ade97 100644 --- a/host/web/navigation/routes.js +++ b/host/web/navigation/routes.js @@ -836,16 +836,12 @@ export const navigation = { routeMatches = matchesRoute; canonicalOf = canonical; // On a touch screen a field with the focus raises its narrow sheet to the tallest (neutral.css, as the keyboard does - // on iOS). A finger's tap on a control in that sheet leaves the focus in the field, as a UIKit control leaves the - // first responder: a mousedown's focus would blur the field and drop the sheet to its detent before the click, - // which would then land beside the control. - let finger = false; - addEventListener("pointerdown", (e) => { - finger = e.pointerType === "touch"; - }, { capture: true, passive: true }); + // on iOS). A press on a control in that sheet, by a finger or by a mouse beside it, leaves the focus in the field, as + // a UIKit control leaves the first responder: a mousedown's focus would blur the field and drop the sheet to its + // detent before the click, which would then land beside the control. addEventListener("mousedown", (e) => { const field = document.activeElement, raised = field?.closest?.("[data-exact-detent]"); - if (finger && raised?.contains(e.target) && field.matches(FIELD) && !e.target.closest?.(`${FIELD}, select, label`) && globalThis.matchMedia?.(RAISES).matches) { + if (raised?.contains(e.target) && field.matches(FIELD) && !e.target.closest?.(`${FIELD}, select, label`) && globalThis.matchMedia?.(RAISES).matches) { e.preventDefault(); } }, true); diff --git a/host/web/tests/sheet-detent.test.mjs b/host/web/tests/sheet-detent.test.mjs index 0416bffd6..c93e1afa6 100644 --- a/host/web/tests/sheet-detent.test.mjs +++ b/host/web/tests/sheet-detent.test.mjs @@ -138,17 +138,20 @@ check('on a touch screen a field with the focus raises the sheet to the tallest, expect(await evaluate(`document.getElementById('field').focus(); box('sheet')`)).toEqual([12, 832]); }), 60000); -check("a finger's tap on a control in a sheet a field's focus raised reaches the control, and the field keeps the focus", () => inChrome(async (evaluate, size, call) => { +check("a press on a control in a sheet a field's focus raised reaches the control, and the field keeps the focus", () => inChrome(async (evaluate, size, call) => { // The case this guards: a route pushed inside a sheet whose field has the focus (an autofocused one). expect(await open(evaluate, 'medium large')).toEqual([428, 416]); await call('Emulation.setTouchEmulationEnabled', { enabled: true, maxTouchPoints: 1 }); await size(390, 844); expect(await evaluate(`select('3'); document.getElementById('pushedField').focus(); box('pushed')`)).toEqual([12, 832]); const [x, y] = await evaluate(`(b => [b.x + b.width / 2, b.y + b.height / 2])(document.getElementById('pushedGo').getBoundingClientRect())`); + const settled = `new Promise(r => setTimeout(r, 300)).then(() => [clicks.splice(0), document.activeElement.id, box('pushed')])`; await call('Input.dispatchTouchEvent', { type: 'touchStart', touchPoints: [{ x, y }] }); await call('Input.dispatchTouchEvent', { type: 'touchEnd', touchPoints: [] }); - expect(await evaluate(`new Promise(r => setTimeout(r, 300)).then(() => [clicks.splice(0), document.activeElement.id, box('pushed')])`)) - .toEqual([['pushedGo'], 'pushedField', [12, 832]]); + expect(await evaluate(settled)).toEqual([['pushedGo'], 'pushedField', [12, 832]]); + // A mouse on the same touch screen: the sheet is raised all the same. + for (const type of ['mousePressed', 'mouseReleased']) await call('Input.dispatchMouseEvent', { type, x, y, button: 'left', buttons: type === 'mousePressed' ? 1 : 0, clickCount: 1 }); + expect(await evaluate(settled)).toEqual([['pushedGo'], 'pushedField', [12, 832]]); }), 60000); check('a bound value keeps the detents UIKit keeps: a word it cannot read or one out of order is dropped', () => inChrome(async (evaluate) => {