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:
1 parent
2c44a19d57
commit
c08e0c7e94
4 files changed
+127
No files matched your search
@@ -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%/);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user