fix(web): keep touch text controls at 16px so mobile Safari stops zooming

Every text control in the console was deliberately smaller than 16px — `input`,
`select` and `textarea` inherit `--fs-body` (14px), `.composer__ta` is 15px — and
on iOS focusing one of those makes Mobile Safari zoom the visual viewport in,
which it does not undo when the keyboard closes. The page stays scaled for the
rest of the session.

app.css now puts the floor in one place: a `@media (hover: none), (max-width:
599px)` rule pins `input/select/textarea/[contenteditable]` at 16px. `hover:
none` covers landscape phones that are wider than 600px, and `!important` is
required because a bare element selector loses to the single-class utilities
that style those controls. `html { text-size-adjust: 100% }` stops the same
kind of resizing on rotation. Desktop (a real pointer) is untouched.

The UI shot harness counts the smallest visible text control per page and fails
a shot under 600px if it is under 16px, so the regression cannot come back
silently; docs/ui-parity.md records the check and why the rule lives in app.css.
This commit is contained in:
yuez committed 2026-10-28 08:14:34 +08:00
1 parent 2c44a19d57
commit c08e0c7e94
4 files changed
+127

No files matched your search

+7
View File
@@ -104,6 +104,7 @@ Per shot, all must pass:
| `page-errors` | `0` | uncaught exceptions (`pageerror`) |
| `api-errors` | `0` | no `/api/v1/*` response ≥ 400 — the fixture contract is complete |
| `no-horizontal-overflow` | `scrollWidth ≤ clientWidth + 1` | no sideways scroll; the report lists the overflowing elements |
| `control-font-size` | `≥16px` (380 px shots only) | a text control under 16px makes Mobile Safari zoom the page in on focus, and it never zooms back out; `app.css` owns the floor (`@media (hover: none), (max-width: 599px)`), `web/tests/mobile-controls.test.ts` pins it |
| `no-tabbar` | `0 × .tabbar` | CHG-04/08: the bottom bar is gone, replaced by the rail + page pill |
| `no-unexpected-modal` | `0 × .modal-backdrop` | the shot shows the page, not a dialog. Pending attention deliberately hangs off `s-attention`, not the session the matrix opens, because the attention modal is blocking and Escape-proof |
| `connect-no-page-pill` / `connect-no-nav-item` | `0` each | `/connect` has no navigation chrome at all |
@@ -246,6 +247,12 @@ state (`/sessions`) and the WS snapshot — so no web code calls them.
外壳:`<600` 顶栏胶囊 + sheet,`600–839` 图标 rail,`≥840` 图标 sidebar(均为 56px)。
Chat:`≥1100` 树 280px + 流,`1000–1099` 树 240px,`<1000` 单栏 + 树抽屉。阅读列 `--reading-max: 52rem`。
输入控件另有一条**不随断点走的最低字号**:`app.css` 在 `@media (hover: none), (max-width: 599px)` 里
把所有 `input/select/textarea/[contenteditable]` 压到 16px。手机 Safari 的聚焦缩放由“控件字号 <16px”
触发且不会自动退出,而设计里 `input` 继承 `--fs-body`(14px)、`.composer__ta` 是 15px,所以这条
`!important` 兜底必须存在;`hover: none` 让横屏(宽于 600px)也被覆盖。桌面鼠标环境不受影响。
`html { text-size-adjust: 100% }` 同时关掉旋转后的文字膨胀。
### 9.3 已知缺口
- `scripts/e2e/ui-e2e.mjs` 需要真 `pi` + nvim 才能跑;本轮只做了选择器适配,未在该环境回归。
+26
View File
@@ -333,6 +333,20 @@ async function collect(page) {
dots: count(".dot"),
modals: count(".modal-backdrop"),
hasRoot: root !== null,
// Smallest visible text-entry control. Mobile Safari zooms the page
// in when one of these is under 16px and never zooms back out.
minControlFont: (() => {
const skip = new Set(["checkbox", "radio", "range", "file", "color", "hidden", "submit", "button", "reset"]);
const sizes = [...document.querySelectorAll("input, select, textarea, [contenteditable='true']")]
.filter((element) => {
const rect = element.getBoundingClientRect();
if (rect.width === 0 || rect.height === 0) return false;
return !(element.tagName === "INPUT" && skip.has(element.type));
})
.map((element) => parseFloat(getComputedStyle(element).fontSize))
.filter((size) => Number.isFinite(size));
return sizes.length ? Math.min(...sizes) : null;
})(),
};
});
}
@@ -452,6 +466,18 @@ async function shootPage(browser, { base, origin, page: spec, viewport, theme, i
}),
);
checks.push(assert("no-tabbar", metrics.tabbar === 0, 0, metrics.tabbar));
// Phone-width shots must keep every text control at ≥16px, otherwise
// Mobile Safari scales the whole page on focus (app.css owns the floor).
if (viewport.width < 600) {
checks.push(
assert(
"control-font-size",
metrics.minControlFont === null || metrics.minControlFont >= 16,
">=16px",
metrics.minControlFont,
),
);
}
// A stray overlay hides the page under a modal: the screenshots must show
// the page, not a dialog nobody asked for.
checks.push(assert("no-unexpected-modal", metrics.modals === 0, 0, metrics.modals));
+15
View File
@@ -53,6 +53,8 @@
* { margin: 0; }
html, body, #root { height: 100%; }
/* No browser-side text inflation: rotating the phone must not resize the page. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
font-family: var(--font-sans);
font-size: var(--fs-body);
@@ -467,6 +469,19 @@ html[data-pi-blink-slow="dim"] .dot--blink-slow { opacity: .35; }
.field .hint.is-err { color: var(--err); }
.field--invalid .input, .field--invalid .textarea, .field--invalid .select { border-color: var(--err); }
/* ---------- touch: keep every text control at 16px ----------
Focusing a text control smaller than 16px makes Mobile Safari zoom the visual
viewport in, and it does not zoom back out when the keyboard closes — the
page stays scaled for the rest of the session. Every control here is
deliberately smaller (`input/select/textarea` inherit `--fs-body` 14px,
`.composer__ta` is 15px), so the floor lives here once instead of in each
component. `!important` because a bare element selector would lose the
cascade to the one-class utilities that style those controls, and the rule
keys on `hover: none` so landscape phones (well past 600px) are covered too. */
@media (hover: none), (max-width: 599px) {
input, select, textarea, [contenteditable="true"] { font-size: 16px !important; }
}
/* ---------- tabs / progress / kv / misc ---------- */
.tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--border-subtle); }
.tab { padding: var(--space-2) var(--space-3); font-size: .875rem; font-weight: 550; color: var(--muted-foreground); border-bottom: 2px solid transparent; margin-bottom: -1px; }
+79
View File
@@ -0,0 +1,79 @@
import { describe, expect, it } from "vitest";
import appCss from "@/styles/app.css?raw";
/**
* The mobile half of the "the console never scales itself" contract.
*
* Two browser behaviours make a phone render the console at the wrong scale,
* both without any help from our CSS:
*
* 1. Mobile Safari zooms the visual viewport in when a focused text control
* renders below 16px, and it never zooms back out — the page stays scaled
* for the whole session. Every control we ship is smaller than that by
* design (`input/select/textarea` inherit `--fs-body` 14px, `.composer__ta`
* is 15px), so `app.css` has to raise a floor.
* 2. Text autosizing inflates type when the device rotates to landscape.
*
* jsdom does not evaluate media queries for `getComputedStyle`, so the sheet is
* read as text (the `?raw` idiom `tokens.test.ts` established).
*/
function stripComments(source: string): string {
return source.replace(/\/\*[\s\S]*?\*\//g, "");
}
/** Every `@media (…) { … }` block in a sheet, as `{ condition, body }`. */
function mediaBlocks(source: string): { condition: string; body: string }[] {
const text = stripComments(source);
const blocks: { condition: string; body: string }[] = [];
const head = /@media([^{]+)\{/g;
let match: RegExpExecArray | null;
while ((match = head.exec(text))) {
const condition = match[1] ?? "";
const open = match.index + match[0].length - 1;
let depth = 0;
for (let i = open; i < text.length; i += 1) {
if (text[i] === "{") depth += 1;
if (text[i] === "}") {
depth -= 1;
if (depth === 0) {
blocks.push({ condition, body: text.slice(open + 1, i) });
head.lastIndex = i;
break;
}
}
}
}
return blocks;
}
const compact = (source: string) => source.replace(/\s+/g, " ").trim();
describe("mobile form controls", () => {
const blocks = mediaBlocks(appCss);
it("keeps text controls at 16px on touch devices, not only on narrow ones", () => {
const guarded = blocks.filter((block) => /font-size:\s*16px\s*!important/.test(compact(block.body)));
expect(guarded.length, "no 16px control floor in app.css").toBeGreaterThan(0);
for (const block of guarded) {
for (const control of ["input", "select", "textarea", '[contenteditable="true"]']) {
expect(compact(block.body), `${block.condition} misses ${control}`).toContain(control);
}
// Phones in landscape are wider than 600px and still zoom.
expect(block.condition, "the floor must key on `hover: none`").toContain("hover: none");
}
});
it("leaves the desktop cascade alone", () => {
for (const block of blocks) {
if (!/font-size:\s*16px\s*!important/.test(compact(block.body))) continue;
expect(block.condition).toMatch(/hover: none|max-width/);
}
});
it("opts out of mobile text autosizing", () => {
expect(compact(appCss)).toMatch(/-webkit-text-size-adjust:\s*100%/);
expect(compact(appCss)).toMatch(/[^-]text-size-adjust:\s*100%/);
});
});