From 0b50fb929a42ef7e43817b5e98cb484da526fa04 Mon Sep 17 00:00:00 2001 From: Void Date: Tue, 10 Nov 2026 18:14:36 +0000 Subject: [PATCH] Phone: 44 px hit areas for sender names, room topic and sign-in links, no layout shift Co-Authored-By: Claude Sonnet 5.5 --- .../components/message/layout/layout.css.ts | 7 ++ src/app/features/room/RoomViewHeader.css.ts | 11 +++ src/app/pages/auth/styles.css.ts | 13 +++ src/app/phoneTapTargets.test.ts | 84 +++++++++++++++++++ 4 files changed, 115 insertions(+) create mode 100644 src/app/phoneTapTargets.test.ts diff --git a/src/app/components/message/layout/layout.css.ts b/src/app/components/message/layout/layout.css.ts index a724241c..9c6b6635 100644 --- a/src/app/components/message/layout/layout.css.ts +++ b/src/app/components/message/layout/layout.css.ts @@ -1,6 +1,7 @@ import { createVar, globalStyle, keyframes, style, styleVariants } from '@vanilla-extract/css'; import { recipe, RecipeVariants } from '@vanilla-extract/recipes'; import { DefaultReset, color, config, toRem } from 'folds'; +import { MOBILE_BREAKPOINT } from '../../../hooks/useScreenSize'; export const StickySection = style({ position: 'sticky', @@ -350,6 +351,9 @@ export const BubbleLeftArrow = style({ zIndex: 1, }); +// Phone tap target: a sender name is 23 px tall, so the button grows 11 px above and below (44+ px to tap) and the +// negative margin takes the growth back out of the layout. Hit area only: no background, border or outline moves. +const SCREEN_PHONE = `screen and (max-width: ${MOBILE_BREAKPOINT}px)`; export const Username = style({ overflow: 'hidden', whiteSpace: 'nowrap', @@ -357,6 +361,9 @@ export const Username = style({ selectors: { 'button&': { cursor: 'pointer', + '@media': { + [SCREEN_PHONE]: { paddingBlock: 11, marginBlock: -11 }, + }, }, 'button&:hover, button&:focus-visible': { textDecoration: 'underline', diff --git a/src/app/features/room/RoomViewHeader.css.ts b/src/app/features/room/RoomViewHeader.css.ts index 19e1afea..cff21a99 100644 --- a/src/app/features/room/RoomViewHeader.css.ts +++ b/src/app/features/room/RoomViewHeader.css.ts @@ -1,7 +1,18 @@ import { style } from '@vanilla-extract/css'; import { config } from 'folds'; +import { MOBILE_BREAKPOINT } from '../../hooks/useScreenSize'; +// Phone tap target: the topic is an 18 px line under the room name; its button grows 9 px up and 17 px down +// (44 px to tap; more below because the name is above) and the negative margin keeps the layout where it was. export const HeaderTopic = style({ + '@media': { + [`screen and (max-width: ${MOBILE_BREAKPOINT}px)`]: { + paddingTop: 9, + paddingBottom: 17, + marginTop: -9, + marginBottom: -17, + }, + }, ':hover': { cursor: 'pointer', opacity: config.opacity.P500, diff --git a/src/app/pages/auth/styles.css.ts b/src/app/pages/auth/styles.css.ts index 5b6b6588..e762207b 100644 --- a/src/app/pages/auth/styles.css.ts +++ b/src/app/pages/auth/styles.css.ts @@ -1,5 +1,6 @@ import { globalStyle, style } from '@vanilla-extract/css'; import { DefaultReset, color, config, toRem } from 'folds'; +import { MOBILE_BREAKPOINT } from '../../hooks/useScreenSize'; import { FOOTER_TINT, PLATE_TINT } from '../../features/scene/skyPlate'; export const AuthLayout = style({ @@ -127,3 +128,15 @@ globalStyle(`${scene} ${AuthFooter}`, { globalStyle(`${scene} ${AuthFooter} a`, { color: 'var(--sky-bubble-text, #b7c7d9)', }); + +// Phone tap targets for the sign-in links, hit area only (every link is under 44 px tall: Forget Password? 16, +// Register 20, the footer's 22): vertical padding grows each link's box and the negative margin takes the growth +// back out of the layout, so nothing moves and nothing is drawn. An inline link ignores the margin and its padding +// never moves a line, which is the same result. +const SCREEN_PHONE = `screen and (max-width: ${MOBILE_BREAKPOINT}px)`; +globalStyle(`${AuthCard} a`, { + '@media': { [SCREEN_PHONE]: { paddingBlock: 14, marginBlock: -14 } }, +}); +globalStyle(`${AuthFooter} a`, { + '@media': { [SCREEN_PHONE]: { paddingBlock: 11, marginBlock: -11 } }, +}); diff --git a/src/app/phoneTapTargets.test.ts b/src/app/phoneTapTargets.test.ts new file mode 100644 index 00000000..57a40bfc --- /dev/null +++ b/src/app/phoneTapTargets.test.ts @@ -0,0 +1,84 @@ +import { describe, expect, it } from 'vitest'; +import zlib from 'zlib'; +import { compile, processVanillaFile } from '@vanilla-extract/integration'; +import { MOBILE_BREAKPOINT } from './hooks/useScreenSize'; + +// The CSS a .css.ts file emits, read back from vanilla-extract's own compile (as pages/auth/footerBand.test.ts does; +// vanilla-extract gzips the inlined source only when it is large, so both forms are read). +const emitted = async (file: string) => { + const filePath = `${process.cwd()}/src/app/${file}`; + const { source } = await compile({ filePath, cwd: process.cwd(), identOption: 'debug' }); + const code = await processVanillaFile({ source, filePath, identOption: 'debug' }); + const bytes = Buffer.from( + (code.match(/source=#?([A-Za-z0-9+/=]+)/) as RegExpMatchArray)[1], + 'base64' + ); + return (bytes[0] === 0x1f && bytes[1] === 0x8b ? zlib.gunzipSync(bytes) : bytes).toString(); +}; + +type Decls = Record; +const parse = (body: string): Decls => + Object.fromEntries( + body + .split('\n') + .map((l) => l.trim().replace(/;$/, '')) + .filter((l) => /^[a-z-]+: -?\d+px$/.test(l)) + .map((l) => [l.split(':')[0], Number(l.split(': ')[1].replace('px', ''))]) + ); + +/** Pixel declarations of the rules whose selector matches, inside or outside a media query. */ +const rulesFor = (css: string, selector: RegExp, media: string | undefined): Decls[] => { + const scope = media + ? [...css.matchAll(/@media ([^{]+) \{\n([\s\S]*?\n)\}(?:\n|$)/g)] + .filter((m) => m[1] === media) + .map((m) => m[2]) + .join('\n') + : css.replace(/@media [^{]+ \{\n[\s\S]*?\n\}(?:\n|$)/g, ''); + return [...scope.matchAll(/^\s*([^{}\n]+) \{\n([^}]*)\}/gm)] + .filter((m) => selector.test(m[1])) + .map((m) => parse(m[2])); +}; + +const PHONE = `screen and (max-width: ${MOBILE_BREAKPOINT}px)`; +const TAP = 44; + +// [target, css file, selector, measured height in CSS px on the Starfire phone run (390x844)]. +const targets: [string, string, RegExp, number][] = [ + [ + 'sender-name button', + 'components/message/layout/layout.css.ts', + /^button\.layout_Username__/, + 23, + ], + [ + 'room-topic button', + 'features/room/RoomViewHeader.css.ts', + /RoomViewHeader_HeaderTopic__\w+$/, + 18, + ], + ['sign-in card links', 'pages/auth/styles.css.ts', /styles_AuthCard__\w+ a$/, 16], + ['sign-in footer links', 'pages/auth/styles.css.ts', /styles_AuthFooter__\w+ a$/, 22], +]; + +describe.each(targets)('phone tap target: %s', (_name, file, selector, height) => { + it(`grows its hit area to ${TAP} px without moving layout`, async () => { + const css = await emitted(file); + const [phone] = rulesFor(css, selector, PHONE); + expect(phone, 'a phone rule exists').toBeDefined(); + const top = phone['padding-top'] ?? phone['padding-block']; + const bottom = phone['padding-bottom'] ?? phone['padding-block']; + const marginTop = phone['margin-top'] ?? phone['margin-block']; + const marginBottom = phone['margin-bottom'] ?? phone['margin-block']; + expect(height + top + bottom).toBeGreaterThanOrEqual(TAP); + // the margin takes back exactly what the padding added, so the target does not move or push its neighbours + expect(marginTop).toBe(-top); + expect(marginBottom).toBe(-bottom); + }); + + it('leaves every other screen as it was: no padding or margin outside the phone query', async () => { + const css = await emitted(file); + rulesFor(css, selector, undefined).forEach((decls) => + expect(Object.keys(decls).filter((k) => /^(padding|margin)/.test(k))).toEqual([]) + ); + }); +});