📱 fix: Keep Focused Text Fields at 16px on Touch Devices (#16971)

This commit is contained in:
Marco Beretta 2026-10-11 22:11:09 +02:00 • committed by GitHub
parent 1bdb8ad811
commit f8ffb4c4e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 159 additions and 1 deletions

View file

@ -703,7 +703,7 @@ const ChatForm = memo(function ChatForm({
const baseClasses = useMemo(
() =>
cn(
'md:py-3.5 m-0 w-full resize-none py-3.25 placeholder:text-text-tertiary bg-transparent [&:has(textarea:focus)]:shadow-[0_2px_6px_rgba(0,0,0,.05)]',
'composer-text md:py-3.5 m-0 w-full resize-none py-3.25 placeholder:text-text-tertiary bg-transparent [&:has(textarea:focus)]:shadow-[0_2px_6px_rgba(0,0,0,.05)]',
isCollapsed ? 'max-h-[3.25rem]' : 'max-h-[45vh] md:max-h-[55vh]',
'px-5',
),

View file

@ -1829,6 +1829,14 @@ html {
font-size: calc(0.9 * var(--markdown-font-size, var(--font-size-base)));
}
/* iOS zooms into a focused field under 16px and the installed PWA never zooms back out. */
@media (any-pointer: coarse) {
.message-editor-text,
.composer-text {
font-size: max(16px, var(--markdown-font-size, var(--font-size-base)));
}
}
.message-content pre {
font-size: var(--markdown-font-size, var(--font-size-base));
}

View file

@ -0,0 +1,91 @@
import { expect, test } from '@playwright/test';
import type { Page } from '@playwright/test';
/**
* iOS zooms into a focused field whose text is under 16px, and the installed PWA
* never zooms back out. A touch device keeps every shared field at 16px or more;
* a pointer-only desktop keeps the compact 14px scale.
*/
const IOS_ZOOM_THRESHOLD = 16;
const loggedOut = { storageState: { cookies: [], origins: [] } };
async function emailFontSize(page: Page): Promise<number> {
await page.goto('/login', { timeout: 10000 });
const email = page.locator('#email');
await expect(email).toBeVisible();
return email.evaluate((node) => parseFloat(getComputedStyle(node).fontSize));
}
test.describe('focused text fields do not trigger iOS zoom', () => {
test.describe('touch device', () => {
test.use({ ...loggedOut, hasTouch: true });
test('the login email field is at least 16px @scenario:touch-login-field-no-zoom', async ({
page,
}) => {
expect(await emailFontSize(page)).toBeGreaterThanOrEqual(IOS_ZOOM_THRESHOLD);
});
});
test.describe('touch device, explicit sizes', () => {
test.use({ ...loggedOut, hasTouch: true });
test('controls sized below 16px are floored and larger ones kept @scenario:touch-explicit-sizes-floored', async ({
page,
}) => {
await page.goto('/login', { timeout: 10000 });
await expect(page.locator('#email')).toBeVisible();
const sizes = await page.evaluate(() => {
const make = (tag: string, className: string, type?: string) => {
const node = document.createElement(tag);
node.className = className;
if (type) {
(node as HTMLInputElement).type = type;
}
document.body.appendChild(node);
return parseFloat(getComputedStyle(node).fontSize);
};
return {
small: make('input', 'text-xs', 'text'),
date: make('input', 'text-sm', 'date'),
area: make('textarea', 'text-sm'),
select: make('select', 'text-sm'),
heading: make('input', 'text-2xl', 'text'),
};
});
expect(sizes.small).toBeGreaterThanOrEqual(IOS_ZOOM_THRESHOLD);
expect(sizes.date).toBeGreaterThanOrEqual(IOS_ZOOM_THRESHOLD);
expect(sizes.area).toBeGreaterThanOrEqual(IOS_ZOOM_THRESHOLD);
expect(sizes.select).toBeGreaterThanOrEqual(IOS_ZOOM_THRESHOLD);
expect(sizes.heading).toBe(24);
});
});
test.describe('pointer only', () => {
test.use(loggedOut);
test('the login email field keeps the compact scale on desktop @scenario:desktop-field-scale-unchanged', async ({
page,
}) => {
const matchesCoarse = await page.evaluate(() => matchMedia('(any-pointer: coarse)').matches);
test.skip(matchesCoarse, 'this project emulates a touch device');
expect(await emailFontSize(page)).toBe(14);
});
});
test.describe('signed in touch device', () => {
test.use({ hasTouch: true });
test('the chat composer is at least 16px @scenario:touch-composer-no-zoom', async ({
page,
}) => {
await page.goto('/c/new', { timeout: 10000 });
const composer = page.getByRole('textbox', { name: 'Message input' });
await expect(composer).toBeVisible();
const size = await composer.evaluate((node) => parseFloat(getComputedStyle(node).fontSize));
expect(size).toBeGreaterThanOrEqual(IOS_ZOOM_THRESHOLD);
});
});
});

View file

@ -79,3 +79,62 @@ html[data-input-modality='pointer'] .lc-field.webkit-dark-styles:focus-visible {
outline: none !important;
}
}
/* iOS zooms into a focused field under 16px and the installed PWA never zooms back out. On touch
devices every text entry control keeps at least 16px, wherever a caller sizes it. Sizes at
text-base or above keep their own value, floored the same way for a small UI scale. This sits in
the package stylesheet so standalone consumers get it too; the composer and message editor in
the app size themselves from the chat font setting and are excluded here. */
@media (any-pointer: coarse) {
:is(
input:not([type]),
input:is(
[type='text'],
[type='email'],
[type='password'],
[type='search'],
[type='url'],
[type='tel'],
[type='number'],
[type='date'],
[type='time'],
[type='datetime-local'],
[type='month'],
[type='week']
),
textarea,
select
) {
&:not(
.text-base,
.text-lg,
.text-xl,
.text-2xl,
.text-3xl,
.message-editor-text,
.composer-text
) {
font-size: max(16px, 0.875rem);
}
&.text-base {
font-size: max(16px, var(--text-base, 1rem));
}
&.text-lg {
font-size: max(16px, var(--text-lg, 1.125rem));
}
&.text-xl {
font-size: max(16px, var(--text-xl, 1.25rem));
}
&.text-2xl {
font-size: max(16px, var(--text-2xl, 1.5rem));
}
&.text-3xl {
font-size: max(16px, var(--text-3xl, 1.875rem));
}
}
}