fix(mobile): one form sheet for every dialog, opaque and placed beside the rail

Every sheet now stands on the opaque sheet surface: the frosting the
translucent one relied on is dropped while the scrim fades, so the page
read through the fields as sharp ghost text.

On a wide window a sheet is centred in the content beside the navigation
rail instead of on the whole window, so it never lies on the rail, and it
grows to the window's height instead of stopping at 880px. On a phone the
card stands between the status bar and the dock rather than across the
dock. A sheet marked as a form fills the height of a window as short as a
phone on its side, with Cancel and Save beside the title (new `short:`
variant, m-form-sheet grid in mobile.css).

The form chrome gains a scrolling body that fades at the edges with more
behind them (useEdgeFade on the vertical axis), a date field whose
keyboard entry moves into the picker, a field wrapper for amounts with a
currency, and two-line titles. The focused sheet no longer draws the
app-wide focus frame or loses its corners, and the desktop's dark field
paint stays out of the touch shell, which painted a dark box inside every
rounded field.
This commit is contained in:
Maurice
2026-11-07 23:19:40 +01:00
parent bb725ac8d8
commit b7a91fc84e
10 changed files with 618 additions and 133 deletions
+73 -3
View File
@@ -43,7 +43,7 @@ describe('MSheet', () => {
expect(onClose).not.toHaveBeenCalled();
const dialog = screen.getByRole('dialog');
const backdrop = dialog.parentElement!.parentElement!;
const backdrop = dialog.closest('[role="presentation"]') as HTMLElement;
fireEvent.click(backdrop);
expect(onClose).toHaveBeenCalledTimes(1);
});
@@ -446,7 +446,7 @@ describe('MSheet', () => {
</MSheet>
);
}
const backdrop = () => screen.getByRole('dialog', { name: 'Form' }).parentElement!.parentElement!;
const backdrop = () => screen.getByRole('dialog', { name: 'Form' }).closest('[role="presentation"]') as HTMLElement;
it('FE-MOB-SHEET-020: a tap on the scrim asks before throwing a change away, and keep editing stays', () => {
const onClose = vi.fn();
@@ -482,5 +482,75 @@ describe('MSheet', () => {
expect(screen.queryByRole('alertdialog')).not.toBeInTheDocument();
});
});
});
describe('presentation', () => {
const panel = (name = 'Sheet') => screen.getByRole('dialog', { name });
const region = (name = 'Sheet') => panel(name).parentElement!.parentElement as HTMLElement;
it('FE-MOB-SHEET-031: every sheet stands on the one opaque surface, whatever material it names', () => {
for (const material of ['glass', 'bar-glass', 'opaque'] as const) {
const { unmount } = render(
<MSheet open onClose={() => {}} material={material} ariaLabel="Sheet">
<span>body</span>
</MSheet>,
);
expect(panel().className).toContain('bg-[color:var(--m-sheetop)]');
expect(panel().className).not.toContain('backdrop-blur');
expect(panel().className).not.toContain('var(--m-sheet)');
expect(panel().className).not.toContain('var(--m-glass)');
unmount();
}
});
it('FE-MOB-SHEET-032: on a phone the card stands between the status bar and the dock, never across the dock', () => {
render(
<MSheet open onClose={() => {}} ariaLabel="Sheet">
<span>body</span>
</MSheet>,
);
expect(region().className).toContain('top-[var(--m-safe-top,12px)]');
expect(region().className).toContain('bottom-[calc(var(--bottom-nav-h,84px)+12px)]');
expect(panel().className).toContain('max-h-full');
});
it('FE-MOB-SHEET-033: a form fills the height of a short window and lays its actions beside the title', () => {
const { unmount } = render(
<MSheet open onClose={() => {}} form ariaLabel="Sheet">
<span>body</span>
</MSheet>,
);
expect(panel().className).toContain('m-form-sheet');
expect(panel().className).toContain('short:flex-1');
expect(region().className).toContain('short:bottom-0');
unmount();
render(
<MSheet open onClose={() => {}} ariaLabel="Sheet">
<span>body</span>
</MSheet>,
);
expect(panel().className).not.toContain('m-form-sheet');
expect(region().className).not.toContain('short:bottom-0');
});
it('FE-MOB-SHEET-034: a transparent scrim still dims a short window, where the sheet takes most of the height', () => {
render(
<MSheet open onClose={() => {}} variant="bottom" dimTransparent ariaLabel="Sheet">
<span>body</span>
</MSheet>,
);
const scrim = panel().closest('[role="presentation"]') as HTMLElement;
expect(scrim.className).toContain('bg-transparent');
expect(scrim.className).toContain('short:bg-[color:var(--m-dim)]');
});
it('FE-MOB-SHEET-035: the region lets taps through to the scrim, the sheet itself takes them', () => {
render(
<MSheet open onClose={() => {}} ariaLabel="Sheet">
<span>body</span>
</MSheet>,
);
expect(region().className).toContain('pointer-events-none');
expect(panel().parentElement!.className).toContain('pointer-events-auto');
});
});
});
+188
View File
@@ -0,0 +1,188 @@
import { act, renderHook } from '@testing-library/react';
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import { useRef, useState } from 'react';
import { describe, expect, it, vi } from 'vitest';
import { useAutoGrow } from '../../../src/hooks/useAutoGrow';
import MSheet from '../../../src/mobile/components/MSheet';
import { edgeFadeClass, useEdgeFade } from '../../../src/mobile/components/useEdgeFade';
import {
FormSheetBody,
FormSheetFooter,
FormSheetHeader,
SheetDateField,
} from '../../../src/mobile/screens/trip/sheets/PlSheetChrome';
import { MemberAvatar } from '../../../src/mobile/screens/trip/tabs/MCostsPayment';
import { fireEvent, render, screen } from '../../helpers/render';
// FE-MOB-FORMSHEET-001 onwards: the form sheet the touch shell presents every
// form in (MSheet `form` + PlSheetChrome), and the stylesheet rules that lay it out.
function Form({ onClose = () => {} }: { onClose?: () => void }) {
return (
<MSheet open onClose={onClose} form ariaLabel="Add expense">
<FormSheetHeader title="Add expense" onClose={onClose} closeLabel="Close" />
<FormSheetBody>
<input aria-label="Name" />
</FormSheetBody>
<FormSheetFooter onCancel={onClose} cancelLabel="Cancel" onSubmit={() => {}} submitLabel="Add" />
</MSheet>
);
}
describe('form sheet chrome', () => {
it('FE-MOB-FORMSHEET-001: header, body and footer carry the parts the short-window layout places', () => {
render(<Form />);
const panel = screen.getByRole('dialog', { name: 'Add expense' });
expect(panel).toHaveClass('m-form-sheet');
const [head, body, foot] = Array.from(panel.children) as HTMLElement[];
expect(head).toHaveClass('m-fs-head');
expect(body).toHaveClass('m-fs-body', 'overflow-y-auto');
expect(foot).toHaveClass('m-fs-foot');
// The close button is the one the layout hides once Cancel stands beside the title.
expect(screen.getByRole('button', { name: 'Close' })).toHaveClass('m-fs-close');
});
it('FE-MOB-FORMSHEET-002: a long title wraps to a second line instead of being cut after one', () => {
render(<Form />);
const title = screen.getAllByText('Add expense').find((el) => el.tagName === 'DIV') as HTMLElement;
expect(title).toHaveClass('line-clamp-2');
expect(title).not.toHaveClass('truncate');
});
it('FE-MOB-FORMSHEET-003: the body is the container its paired rows measure against', () => {
render(<Form />);
const body = screen.getByRole('textbox', { name: 'Name' }).parentElement as HTMLElement;
expect(body.className).toContain('[container-type:inline-size]');
});
it('FE-MOB-FORMSHEET-004: the body fades at the foot while more waits below, and at the top once scrolled', () => {
render(<Form />);
const body = screen.getByRole('textbox', { name: 'Name' }).parentElement as HTMLElement;
Object.defineProperty(body, 'scrollHeight', { configurable: true, value: 900 });
Object.defineProperty(body, 'clientHeight', { configurable: true, value: 400 });
act(() => {
body.dispatchEvent(new Event('scroll'));
});
expect(body).toHaveClass('m-fade-b');
act(() => {
body.scrollTop = 200;
body.dispatchEvent(new Event('scroll'));
});
expect(body).toHaveClass('m-fade-tb');
act(() => {
body.scrollTop = 500;
body.dispatchEvent(new Event('scroll'));
});
expect(body).toHaveClass('m-fade-t');
});
it('FE-MOB-FORMSHEET-005: the date field keeps its keyboard entry in the picker, so the date has the field to itself', () => {
render(<SheetDateField value="2026-11-07" onChange={() => {}} />);
// No second round button beside the date taking its room.
expect(screen.queryByRole('button', { name: /enter date manually|common\.datepicker\.enterManually/i })).toBeNull();
const trigger = screen.getByRole('button', { expanded: false });
fireEvent.click(trigger);
expect(
screen.getByRole('button', { name: /enter date manually|common\.datepicker\.enterManually/i })
).toBeInTheDocument();
expect(trigger.closest('.rounded-full')).not.toBeNull();
});
});
describe('useEdgeFade on the vertical axis', () => {
function box(scrollHeight: number, clientHeight: number, scrollTop = 0) {
const el = document.createElement('div');
Object.defineProperty(el, 'scrollHeight', { configurable: true, value: scrollHeight });
Object.defineProperty(el, 'clientHeight', { configurable: true, value: clientHeight });
el.scrollTop = scrollTop;
return el;
}
it('FE-MOB-FORMSHEET-006: reads the top and the foot, and its classes never mirror', () => {
expect(edgeFadeClass(renderHook(() => useEdgeFade(box(400, 400), 'y')).result.current, 'y')).toBe('');
expect(edgeFadeClass(renderHook(() => useEdgeFade(box(900, 400), 'y')).result.current, 'y')).toBe('m-fade-b');
expect(edgeFadeClass({ start: true, end: false }, 'y')).toBe('m-fade-t');
expect(edgeFadeClass({ start: true, end: true }, 'y')).toBe('m-fade-tb');
// The strip's own classes are unchanged.
expect(edgeFadeClass({ start: true, end: true })).toBe('m-fade-se');
});
it('FE-MOB-FORMSHEET-007: measures again when fields come and go inside a box that keeps its height', async () => {
const el = box(400, 400);
const { result } = renderHook(() => useEdgeFade(el, 'y'));
expect(result.current.end).toBe(false);
Object.defineProperty(el, 'scrollHeight', { configurable: true, value: 800 });
await act(async () => {
el.appendChild(document.createElement('div'));
await Promise.resolve();
});
expect(result.current.end).toBe(true);
});
});
describe('useAutoGrow', () => {
it('FE-MOB-FORMSHEET-008: a textarea grows to its lines instead of slicing the last one', () => {
function Story() {
const ref = useRef<HTMLTextAreaElement>(null);
const [text, setText] = useState('one');
useAutoGrow(ref, text);
return <textarea ref={ref} aria-label="Story" rows={3} value={text} onChange={(e) => setText(e.target.value)} />;
}
const scrollHeight = vi.spyOn(HTMLTextAreaElement.prototype, 'scrollHeight', 'get').mockReturnValue(66);
render(<Story />);
const area = screen.getByRole('textbox', { name: 'Story' });
expect(area.style.height).toBe('66px');
scrollHeight.mockReturnValue(110);
fireEvent.change(area, { target: { value: 'one\ntwo\nthree\nfour' } });
expect(area.style.height).toBe('110px');
scrollHeight.mockRestore();
});
});
describe('MemberAvatar', () => {
it('FE-MOB-FORMSHEET-009: shows the member initial, and turns over on a chip filled with the accent', () => {
const { rerender } = render(<MemberAvatar name="alice" variant="accent" size={16} />);
expect(screen.getByText('A')).toHaveClass('bg-m-act', 'text-m-actfg');
rerender(<MemberAvatar name="alice" variant="onAccent" size={16} />);
expect(screen.getByText('A')).toHaveClass('bg-m-actfg', 'text-m-act');
});
});
describe('form sheet stylesheet', () => {
// jsdom applies no stylesheet, so these read the real files. Vitest runs with
// the client package as its root.
const mobileCss = readFileSync(resolve(process.cwd(), 'src/mobile/mobile.css'), 'utf8');
const indexCss = readFileSync(resolve(process.cwd(), 'src/index.css'), 'utf8');
const tailwind = readFileSync(resolve(process.cwd(), 'tailwind.config.js'), 'utf8');
const shortBlock = (() => {
const start = mobileCss.indexOf('@media (max-height: 500px)');
return mobileCss.slice(start, mobileCss.indexOf('\n}\n', start));
})();
it('FE-MOB-FORMSHEET-010: the short-window variant is the other side of the wide size class height bound', () => {
expect(tailwind).toContain("addVariant('short', '@media (max-height: 500px)')");
expect(tailwind).toContain("addVariant('wide', '@media (min-width: 600px) and (min-height: 501px)')");
});
it('FE-MOB-FORMSHEET-011: on a short window the actions sit beside the title and the fields take the rest', () => {
expect(shortBlock).toContain('.m-form-sheet.m-form-sheet {');
expect(shortBlock).toMatch(/display: grid;/);
expect(shortBlock).toMatch(/\.m-fs-foot \{[^}]*grid-area: 1 \/ 2;[^}]*border-top: 0;/);
expect(shortBlock).toMatch(/\.m-fs-body \{[^}]*grid-row: 3;/);
// Cancel then does the close button's job; a form without a footer keeps it.
expect(shortBlock).toContain('.m-form-sheet:has(> .m-fs-foot) > .m-fs-head .m-fs-close');
});
it('FE-MOB-FORMSHEET-012: the focused sheet keeps its corners and draws no focus frame', () => {
expect(mobileCss).toMatch(
/\.m-root \[data-m-sheet\]:focus-visible \{\s*outline: none;\s*border-radius: var\(--m-sheet-r\);/
);
});
it("FE-MOB-FORMSHEET-013: the desktop's dark field paint stays out of the touch shell", () => {
expect(indexCss).toContain('.dark input:not(:where(.m-root *))');
expect(indexCss).toContain('.dark textarea:not(:where(.m-root *))');
expect(indexCss).not.toMatch(/^\.dark input, \.dark textarea, \.dark select \{/m);
});
});
+21 -13
View File
@@ -15,17 +15,24 @@ import { resetAllStores, seedStore } from '../../helpers/store';
// FE-MOB-LARGE-001 onwards: the touch shell's pieces laid out for a wide window.
describe('MSheet on a wide window', () => {
it('FE-MOB-LARGE-001: a sheet becomes a centred form sheet of the width it asks for', () => {
// dialog > its box (width, arrow) > the region it stands in (place on the screen).
const boxOf = (name: string) => screen.getByRole('dialog', { name }).parentElement as HTMLElement;
const regionOf = (name: string) => boxOf(name).parentElement as HTMLElement;
it('FE-MOB-LARGE-001: a sheet becomes a form sheet centred in the content beside the rail, of the width it asks for', () => {
render(
<MSheet open onClose={() => {}} variant="bottom" wideWidth="large" ariaLabel="Form">
<span>body</span>
</MSheet>
);
const frame = screen.getByRole('dialog', { name: 'Form' }).parentElement as HTMLElement;
expect(frame.className).toContain('wide:mx-auto');
expect(frame.className).toContain('wide:top-1/2');
expect(frame.className).toContain('wide:w-[min(720px,calc(100%-48px))]');
expect(frame.querySelector('[aria-hidden="true"].wide\\:block')).toBeNull();
const region = regionOf('Form');
// The region starts after the rail, so the sheet is centred in what is left of the window.
expect(region.className).toContain('wide:ps-[calc(var(--m-rail-w)+24px)]');
expect(region.className).toContain('wide:pe-6');
expect(region.className).toContain('wide:justify-center');
expect(region.className).toContain('wide:items-center');
expect(boxOf('Form').className).toContain('wide:w-[min(720px,100%)]');
expect(boxOf('Form').querySelector(':scope > span[aria-hidden="true"]')).toBeNull();
});
it("FE-MOB-LARGE-002: a menu from the rail's foot is a popover beside it, with an arrow", () => {
@@ -42,11 +49,12 @@ describe('MSheet on a wide window', () => {
<span>body</span>
</MSheet>
);
const frame = screen.getByRole('dialog', { name: 'More' }).parentElement as HTMLElement;
expect(frame.className).toContain('wide:start-[calc(var(--m-rail-w)+6px)]');
expect(frame.className).not.toContain('wide:mx-auto');
expect(frame.className).toContain('wide:w-[min(320px,calc(100%-48px))]');
expect(frame.querySelector(':scope > span[aria-hidden="true"]')).not.toBeNull();
const region = regionOf('More');
expect(region.className).toContain('wide:ps-[calc(var(--m-rail-w)+6px)]');
expect(region.className).toContain('wide:justify-end');
expect(region.className).not.toContain('wide:justify-center');
expect(boxOf('More').className).toContain('wide:w-[min(320px,100%)]');
expect(boxOf('More').querySelector(':scope > span[aria-hidden="true"]')).not.toBeNull();
});
it('FE-MOB-LARGE-003: the drawer keeps its own place', () => {
@@ -55,8 +63,8 @@ describe('MSheet on a wide window', () => {
<span>body</span>
</MSheet>
);
const frame = screen.getByRole('dialog', { name: 'Drawer' }).parentElement as HTMLElement;
expect(frame.className).not.toContain('wide:');
expect(regionOf('Drawer').className).not.toContain('wide:');
expect(boxOf('Drawer').className).not.toContain('wide:');
});
});