Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions host/web/navigation/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -832,6 +835,16 @@ 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 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 (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",
Expand Down
20 changes: 19 additions & 1 deletion host/web/tests/sheet-detent.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const abs = 'position:absolute;inset:0;display:flex;flex-direction:column';
const page = '<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">' + style + `<div id="exact-root"><main id="nav" navigationKey="1" navigationBack="back" style="width:100%;height:100%;position:relative">
<div navigationKey="1" id="home" style="${abs}"><header><h1>Home</h1></header></div>
<div navigationKey="2" id="sheet" navigationPresentation="modal" style="${abs}"><header><h2>Sheet</h2></header><div id="rows" style="height:120px"></div><input id="field"></div>
<div navigationKey="3" id="pushed" style="${abs}"><header><h2>Pushed</h2></header></div>
<div navigationKey="3" id="pushed" style="${abs}"><header><h2>Pushed</h2></header><input id="pushedField"><button id="pushedGo">Go</button></div>
<div navigationKey="4" id="over" navigationPresentation="modal" style="${abs}"><header><h2>Over</h2></header></div>
<div navigationKey="5" id="full" navigationPresentation="fullscreen" style="${abs};background:black"><header><h2>Full</h2></header></div>
<div navigationKey="6" id="top" navigationPresentation="modal" style="${abs}"><header><h2>Top</h2></header></div>
Expand All @@ -43,6 +43,8 @@ const page = '<meta name="viewport" content="width=device-width, initial-scale=1
said == null ? e.removeAttribute('data-navigationdetent') : e.setAttribute('data-navigationdetent', said);
initial == null ? e.removeAttribute('data-navigationinitialdetent') : e.setAttribute('data-navigationinitialdetent', initial);
};
window.clicks = [];
document.addEventListener('click', e => clicks.push(e.target.id), true);
window.shown = id => getComputedStyle(document.getElementById(id)).visibility === 'visible';
window.box = id => { const e = document.getElementById(id); e.getAnimations().forEach(a => a.finish()); const b = e.getBoundingClientRect(); return [b.y, b.height].map(v => Math.round(v * 10) / 10); };
select('1');
Expand Down Expand Up @@ -136,6 +138,22 @@ 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 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(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) => {
expect(await open(evaluate, '0% large')).toEqual([12, 832]);
expect(await open(evaluate, 'tall 300 large')).toEqual([544, 300]);
Expand Down
Loading