Public: anyone can read this; the crew can change it.

Phones: every control is a 44 px target, every button has a name (#16427 keeps diff lines readable) #16491

opened this

Check · Review · Land · Live — No review yet. Next: reviewer, no review yet.

Ready to land

talk-phone → main 1 commit

Review

Sign in to review this change.
9 files changed +228 −25
docs/design/areas/touch.md added +15
@@ -0,0 +1,15 @@
1 # Touch
2
3 Under a finger (`@media (pointer: coarse)`), every control on a page is at least 44 px each way;
4 with a mouse the sizes are the components' own. The rule sits last in `src/web/style/components.ts`
5 so a smaller size set earlier (a small button, a tab, a menu row) gives way to it, and a hit area an
6 `::after` widened in Talk gives way to the real size, so it never covers its neighbour. A link
7 inside a sentence is text and keeps its size (WCAG 2.5.8's inline exception). A diff's lines keep
8 their reading height (45 a screen at 390 px): the whole row is a line's tap target, with a 44 px bar
9 under a tapped line (#16427), so a line number is not sized here. The bar's own height
10 (`--topbar-h`) grows with its controls, so what sticks under it starts below it.
11
12 - `.keys-only`: a keyboard's hint ("Ctrl/Cmd+Enter sends"), not shown under a finger.
13
14 Proof: `test/phone-targets.test.ts` measures a pull, its Files and Talk at 390 × 844 with touch on,
15 from each control's centre 21 px each way, and asks every button for a name.
docs/design/size-budget.json +17 −17
@@ -1,31 +1,31 @@
11 {
22 "/": {
33 "js": 22016,
4 "css": 48640
4 "css": 49920
55 },
66 "/explore": {
77 "js": 21760,
8 "css": 48640
8 "css": 49920
99 },
1010 "/map": {
1111 "js": 28672,
12 "css": 50304
12 "css": 51712
1313 },
1414 "/:owner/:name": {
1515 "js": 38400,
16 "css": 48640
16 "css": 49920
1717 },
1818 "/changelog": {
1919 "js": 26880,
20 "css": 48640
20 "css": 49920
2121 },
2222 "/:owner/:name/next": {
2323 "js": 23296,
24 "css": 49024
24 "css": 50176
2525 },
2626 "/:owner/:name/space": {
2727 "js": 30208,
28 "css": 49792
28 "css": 50944
2929 },
3030 "/:owner/:name/space.json": {
3131 "js": 0,
@@ -33,39 +33,39 @@
3333 },
3434 "/maintenance": {
3535 "js": 21760,
36 "css": 48640
36 "css": 49920
3737 },
3838 "/pricing": {
3939 "js": 21760,
40 "css": 48640
40 "css": 49920
4141 },
4242 "/forges/new": {
4343 "js": 21760,
44 "css": 48640
44 "css": 49920
4545 },
4646 "/claim": {
4747 "js": 24320,
48 "css": 48640
48 "css": 49920
4949 },
5050 "/templates": {
5151 "js": 21760,
52 "css": 48640
52 "css": 49920
5353 },
5454 "/system": {
5555 "js": 23808,
56 "css": 48640
56 "css": 49920
5757 },
5858 "/feed": {
5959 "js": 36352,
60 "css": 48640
60 "css": 49920
6161 },
6262 "/board": {
6363 "js": 26880,
64 "css": 48640
64 "css": 49920
6565 },
6666 "/fleet": {
6767 "js": 21760,
68 "css": 48640
68 "css": 49920
6969 },
7070 "/talk": {
7171 "js": 40960,
@@ -73,6 +73,6 @@
7373 },
7474 "/:owner/:name/pulls/:number": {
7575 "js": 32000,
76 "css": 48640
76 "css": 49920
7777 }
7878 }
src/web/pages/talk.ts +1 −1
@@ -676,7 +676,7 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string |
676676 ${buildMode ? html`<p class="talk-foot small"><a href="${here}">Talk instead</a></p>` : null}
677677 <p class="talk-error small" id="talk-error" data-error hidden></p>
678678 <p class="talk-status small muted" role="status">${running ? "The forge is answering…" : ""}</p>
679 <button type="button" class="btn talk-jump" data-jump hidden>${icon("pause")}${icon("arrowDown")}<span data-word></span><i class="talk-dot"></i></button>
679 <button type="button" class="btn talk-jump" data-jump hidden title="Jump to the latest message">${icon("pause")}${icon("arrowDown")}<span data-word></span><i class="talk-dot"></i></button>
680680 </form>
681681 <template id="talk-ico">${icon("copy")}${icon("check")}</template>
682682 </div>
src/web/studio/feed.ts +1 −1
@@ -327,7 +327,7 @@ export function composer(ctx: Ctx, user: User): Html {
327327 <option value="${FORGE_TARGET}">the forge</option>
328328 </select>`}
329329 <span class="spacer"></span>
330 <span class="muted small">Ctrl/Cmd+Enter sends</span>
330 <span class="muted small keys-only">Ctrl/Cmd+Enter sends</span>
331331 ${btn("Post", { variant: "primary" })}
332332 </div>
333333 </form>`;
src/web/style/components.ts +11 −4
@@ -67,12 +67,9 @@ export const components = /* css */ `
6767 .btn-icon[data-size="lg"] { width: 44px; min-width: 44px; }
6868 .talk-btn { position: relative; }
6969 .talk-count { position: absolute; top: 0; right: 2px; font-size: 12.5px; line-height: 1; font-weight: 600; color: var(--fg); pointer-events: none; }
70 /* Touch targets stay thumb-sized on a phone; padding does it, so text stays centered. */
70 /* Touch targets are thumb-sized on a phone; the rest of the rule is last in this sheet. */
7171 @media (pointer: coarse) {
7272 .btn { min-height: 44px; }
73 .btn[data-size="sm"] { min-height: 36px; }
74 .btn-icon { width: 44px; min-width: 44px; }
75 .btn-icon[data-size="sm"] { width: 36px; min-width: 36px; }
7673 }
7774
7875 /* ---- form controls ---- */
@@ -1373,4 +1370,14 @@ ul.list { overflow-anchor: none; }
13731370 white-space: normal; overflow-wrap: anywhere;
13741371 }
13751372 :is(#crew-now, #next-steps) .input { max-width: 100%; box-sizing: border-box; }
1373 /* Under a finger, 44px each way (docs/design/areas/touch.md). */
1374 @media (pointer: coarse) {
1375 :root { --topbar-h: 62px; }
1376 .btn[data-size], .input, .topbar-search input, .tabs > a, .seg > a, .menu-item, .where-place, summary, label.check, .diff-viewed { min-height: 44px; }
1377 .btn-icon, .btn-icon[data-size], .talk-page .talk :is(.talk-act, .talk-copy) { width: 44px; min-width: 44px; height: 44px; }
1378 .seg > a, label.check, .diff-viewed, .crumbs a, .repo-title a, .byline a, .foot a { display: inline-flex; align-items: center; }
1379 .crumbs a, .repo-title a, .byline a, .foot a { justify-content: center; min-width: 44px; min-height: 44px; }
1380 .talk-page .talk :is(.btn-icon, summary.btn, .talk-copy, .talk-act, .talk-code-head .talk-copy)::after { inset: 0; }
1381 .keys-only { display: none; }
1382 }
13761383 `;
src/web/style/content.ts −1
@@ -57,7 +57,6 @@ a.where-place:hover, button.where-place:hover {
5757 }
5858 .where-place .ico { color: var(--faint); flex: none; }
5959 /* A thumb needs more than a 12px word to land on. */
60 @media (pointer: coarse) { .where-place { min-height: 32px; padding: 4px 8px; } }
6160 /* The dot is the place's aria-hidden span: ● ○ ◆ are decoration, and the
6261 state and the word beside them already say what they mean. */
6362 .where-place > span[aria-hidden="true"] { font-size: var(--fs-min); line-height: 1; }
test/helpers/chrome.ts +3
@@ -143,6 +143,8 @@ export async function evaluateLoaded(
143143 cookies: { name: string; value: string }[],
144144 expression: string,
145145 scheme: "light" | "dark" = "light",
146 /** A finger, not a mouse: touch events on, so `(pointer: coarse)` holds as on a phone. */
147 touch = false,
146148 ): Promise<string> {
147149 const profile = mkdtempSync(join(tmpdir(), "forge-phone-"));
148150 const proc = start(binary, profile);
@@ -178,6 +180,7 @@ export async function evaluateLoaded(
178180 await cdp.send("Emulation.setEmulatedMedia", {
179181 features: [{ name: "prefers-color-scheme", value: scheme }],
180182 });
183 if (touch) await cdp.send("Emulation.setTouchEmulationEnabled", { enabled: true, maxTouchPoints: 5 });
181184 for (const cookie of cookies)
182185 await cdp.send("Network.setCookie", {
183186 name: cookie.name,
test/phone-targets.test.ts added +179
@@ -0,0 +1,179 @@
1 /**
2 * A finger on a phone (390×844, a coarse pointer), measured in a real Chromium on a pull, its Files
3 * and Talk: every control is at least 44 px each way, and every button has a name a screen reader
4 * says. A link inside a sentence is text, not a target, and is left out (WCAG 2.5.8's inline
5 * exception): one whose surrounding words hold a letter. A checkbox counts by its label when it has
6 * one. Skipped, and says so, where no Chromium starts.
7 */
8 import { afterAll, beforeAll, expect, test } from "bun:test";
9 import { mkdtemp, rm } from "node:fs/promises";
10 import { tmpdir } from "node:os";
11 import { join } from "node:path";
12 import { openPull } from "../src/actions/pulls.ts";
13 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
14 import { createApp, type App } from "../src/app.ts";
15 import { appendTurn, openConversation } from "../src/core/conversations.ts";
16 import { createSession } from "../src/core/sessions.ts";
17 import { createUser } from "../src/core/users.ts";
18 import { findChromium } from "../src/looks/capture.ts";
19 import { serve, type Servers } from "../src/http/server.ts";
20 import { chromiumRuns, evaluateLoaded } from "./helpers/chrome.ts";
21 import { quietLogs } from "./helpers/globals.ts";
22 import { promote } from "./helpers/members.ts";
23
24 quietLogs();
25
26 const found = findChromium();
27 const chromium = found !== undefined && chromiumRuns(found) ? found : undefined;
28 if (chromium === undefined)
29 console.log(
30 "SKIPPING: no chromium that starts on this machine, so tap targets are not measured",
31 );
32
33 let dir: string;
34 let app: App;
35 let servers: Servers;
36 let token: string;
37 let pull = 0;
38
39 beforeAll(async () => {
40 dir = await mkdtemp(join(tmpdir(), "forge-phone-targets-"));
41 app = createApp({ dataDir: dir, port: 0 });
42 servers = await serve(app);
43 const made = await createUser(app.db, {
44 origin: "seed",
45 trusted: true,
46 username: "alice",
47 email: "[email protected]",
48 password: "a-good-passphrase",
49 adminIfFirst: true,
50 });
51 if (!made.ok) throw new Error(made.error);
52 const alice = made.value;
53 promote(app.db, alice);
54 const repo = await createRepo(app, alice, {
55 name: "voxel",
56 visibility: "public",
57 });
58 if (!repo.ok) throw new Error(String(repo.error));
59 const lines = (k: number) =>
60 Array.from(
61 { length: 12 },
62 (_, i) => `const a${String(i)} = ${String(i * k)};`,
63 ).join("\n") + "\n";
64 await commitToBranch(app, alice, repo.value, {
65 branch: "main",
66 message: "first",
67 files: [{ path: "src/a.ts", content: lines(1) }],
68 });
69 await commitToBranch(app, alice, repo.value, {
70 branch: "double",
71 message: "Double them",
72 files: [{ path: "src/a.ts", content: lines(2) }],
73 });
74 const opened = await openPull(app, alice, repo.value, {
75 title: "Double them",
76 body: "Twice as much.",
77 baseBranch: "main",
78 headBranch: "double",
79 });
80 if (!opened.ok) throw new Error(String(opened.error));
81 pull = opened.value.number;
82 const chat = openConversation(app.db, alice.id);
83 appendTurn(app.db, alice.id, chat.id, { role: "person", text: "hello" });
84 appendTurn(app.db, alice.id, chat.id, {
85 role: "agent",
86 text: "Hello.\n\n```ts\nconst x = 1;\n```\n",
87 });
88 token = createSession(app.db, alice.id).token;
89 }, 30_000);
90 afterAll(async () => {
91 servers.stop();
92 app.close();
93 await rm(dir, { recursive: true, force: true });
94 });
95
96 /**
97 * Every control whose tap area is under 44 px, and every button with no name, as `tag.class "words"`.
98 * The tap area is what a finger hits, not the box drawn: from the control's centre, 21 px left,
99 * right, up and down must each land on the control (an `::after` that widens the hit area counts;
100 * a neighbour on top does not). Names are asked of every button, shown or not yet shown.
101 */
102 const EXPRESSION = `(() => {
103 const coarse = matchMedia("(pointer: coarse)").matches;
104 const say = (el) => el.tagName.toLowerCase() + (el.getAttribute("name") ? "[name=" + el.getAttribute("name") + "]" : "") + (typeof el.className === "string" && el.className ? "." + el.className.trim().split(/\\s+/).join(".") : "") + ' "' + (el.textContent || "").replace(/\\s+/g, " ").trim().slice(0, 24) + '"';
105 const inSentence = (el) => {
106 if (el.tagName !== "A" || getComputedStyle(el).display !== "inline") return false;
107 const around = (el.parentElement ? el.parentElement.textContent : "").replace(el.textContent || "", "");
108 return /\\p{L}/u.test(around);
109 };
110 const hits = (el, x, y) => {
111 if (x < 0 || y < 0 || x >= innerWidth || y >= innerHeight) return true;
112 const at = document.elementFromPoint(x, y);
113 return !!at && (at === el || el.contains(at) || (el.labels && [...el.labels].some((l) => l === at || l.contains(at))));
114 };
115 const small = [], unnamed = [];
116 const controls = 'a[href], button, summary, select, textarea, input:not([type="hidden"]), [role="button"], [role="tab"]';
117 for (const el of document.querySelectorAll("button, [role=button], a.btn-icon, summary.btn-icon")) {
118 const name = (el.getAttribute("aria-label") || el.getAttribute("title") || el.textContent || (el.getAttribute("aria-labelledby") ? "labelled" : "")).trim();
119 if (name === "") unnamed.push(say(el));
120 }
121 for (const el of document.querySelectorAll(controls)) {
122 // A diff line keeps its reading height, and the whole row is its tap target (#16427): its number is covered by the row.
123 if (el.getClientRects().length === 0 || getComputedStyle(el).visibility === "hidden" || inSentence(el) || el.matches(".dn-comment")) continue;
124 // Brought into view only as far as it is not, in the window and in any box that scrolls it
125 // (a row of tabs): a sticky head moved away would hide what it holds.
126 el.scrollIntoView({ block: "nearest", inline: "nearest" });
127 const r = el.getBoundingClientRect();
128 if (r.bottom <= 0 || r.right <= 0 || r.width === 0) continue;
129 const cx = r.left + r.width / 2, cy = r.top + r.height / 2;
130 if (!hits(el, cx, cy)) continue;
131 if (![[cx - 21, cy], [cx + 21, cy], [cx, cy - 21], [cx, cy + 21]].every(([x, y]) => hits(el, x, y))) small.push(say(el) + " " + Math.round(r.width) + "x" + Math.round(r.height));
132 }
133 return JSON.stringify({ coarse, small: [...new Set(small)], unnamed: [...new Set(unnamed)] });
134 })()`;
135
136 const look = async (
137 path: string,
138 ): Promise<{ coarse: boolean; small: string[]; unnamed: string[] }> =>
139 JSON.parse(
140 await evaluateLoaded(
141 chromium!,
142 `${servers.url}${path}`,
143 { width: 390, height: 844 },
144 [{ name: "forge_session", value: token }],
145 EXPRESSION,
146 "light",
147 true,
148 ),
149 ) as { coarse: boolean; small: string[]; unnamed: string[] };
150
151 test.skipIf(chromium === undefined)("a key's hint (`keys-only`, the home composer's \"Ctrl/Cmd+Enter sends\") is not shown under a finger", async () => {
152 const boxes = await evaluateLoaded(chromium!, `${servers.url}/talk`, { width: 390, height: 844 }, [{ name: "forge_session", value: token }], "(() => { const s = document.createElement('span'); s.className = 'muted small keys-only'; s.textContent = 'Ctrl/Cmd+Enter sends'; document.body.append(s); return JSON.stringify(s.getClientRects().length); })()", "light", true);
153 expect(boxes).toBe("0");
154 expect(await Bun.file("src/web/studio/feed.ts").text()).toContain('<span class="muted small keys-only">Ctrl/Cmd+Enter sends</span>');
155 }, 60_000);
156
157 test.skipIf(chromium === undefined)("a diff's lines keep their reading height under a finger: as many lines on a 390 px screen as with a mouse", async () => {
158 const lines = (touch: boolean) => evaluateLoaded(chromium!, `${servers.url}/alice/voxel/pulls/${String(pull)}/files`, { width: 390, height: 844 }, [{ name: "forge_session", value: token }], "JSON.stringify(Math.round(document.querySelector('.dn-comment').closest('tr').getBoundingClientRect().height * 10) / 10)", "light", touch);
159 const [finger, mouse] = [await lines(true), await lines(false)];
160 expect(Number(finger)).toBeLessThan(30);
161 expect(finger).toBe(mouse);
162 }, 60_000);
163
164 for (const [what, path] of [
165 ["a pull", () => `/alice/voxel/pulls/${String(pull)}`],
166 ["a pull's Files", () => `/alice/voxel/pulls/${String(pull)}/files`],
167 ["Talk", () => "/talk"],
168 ["Talk's list of conversations", () => "/talk?chats=1"],
169 ] as const)
170 test.skipIf(chromium === undefined)(
171 `${what}: every control is 44 px each way under a finger, and every button has a name`,
172 async () => {
173 const seen = await look(path());
174 expect(seen.coarse).toBe(true);
175 expect(seen.small).toEqual([]);
176 expect(seen.unnamed).toEqual([]);
177 },
178 60_000,
179 );
test/talk-page.test.ts +1 −1
@@ -210,7 +210,7 @@ describe("the page", () => {
210210 expect(empty).toContain('name="text" value="What is waiting for me?"');
211211 // Copy is the script's; the follow control is drawn hidden and only the script shows it.
212212 expect(empty).not.toMatch(/<button[^>]*data-copy/);
213 expect(empty).toMatch(/<button type="button" class="btn talk-jump" data-jump hidden>/);
213 expect(empty).toMatch(/<button type="button" class="btn talk-jump" data-jump hidden title="Jump to the latest message">/);
214214 say(carol.value, "person", "hi");
215215 say(carol.value, "agent", "hello");
216216 say(carol.value, "tool", "list_issues {\"repo\":\"x\"}");

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs