diff --git a/apps/app/e2e/harness/dialog.tsx b/apps/app/e2e/harness/dialog.tsx index 62b15716..57f0a58a 100644 --- a/apps/app/e2e/harness/dialog.tsx +++ b/apps/app/e2e/harness/dialog.tsx @@ -17,7 +17,11 @@ const lang: Locale = useLocaleStore.setState({ locale: lang }) document.documentElement.lang = lang -type Scenario = 'basic' | 'long' | 'guarded' | 'vanishing' | null +/** Wraps on a phone: the close button must keep its 44 px box beside it. */ +const LONG_TITLE = + 'A dialog title long enough to wrap over several lines on a narrow phone screen' + +type Scenario = 'basic' | 'long' | 'title' | 'guarded' | 'vanishing' | null function Background({ onOpen }: { onOpen: (scenario: Scenario) => void }) { const [clicks, setClicks] = useState(0) @@ -26,6 +30,7 @@ function Background({ onOpen }: { onOpen: (scenario: Scenario) => void }) {
+
+ + + + !busy && close()} diff --git a/apps/app/e2e/ui/dialog.spec.ts b/apps/app/e2e/ui/dialog.spec.ts index 833b6bb0..80ec240b 100644 --- a/apps/app/e2e/ui/dialog.spec.ts +++ b/apps/app/e2e/ui/dialog.spec.ts @@ -198,6 +198,31 @@ test('fits the viewport without horizontal page scroll', async ({ page }) => { } }) +// Rev 6: the ✕ is a 44 × 44 px touch box (MobileDrawer's), never squeezed by a long title. +test('the close button is a 44 px box beside a long title at 320, 375 and 1280 px', async ({ + page, +}) => { + const title = + 'A dialog title long enough to wrap over several lines on a narrow phone screen' + const dialog = await openScenario(page, 'Open wrapped title', title) + const close = dialog.getByRole('button', { name: fr['common.close'] }) + for (const width of [320, 375, 1280]) { + await page.setViewportSize({ width, height: 700 }) + // Polled: the panel scales in (0.96 to 1) right after it opens. + const box = async () => (await close.boundingBox())! + await expect + .poll(async () => (await box()).width, { message: `✕ width at ${width}` }) + .toBeGreaterThanOrEqual(44) + expect((await box()).height, `✕ height at ${width}`).toBeGreaterThanOrEqual( + 44, + ) + const { x, width: size } = await box() + expect(x + size, `✕ inside at ${width}`).toBeLessThanOrEqual(width + 0.5) + await expectNoHorizontalOverflow(page, `the long title at ${width}`) + } + await expectAccessible(page, 'the long-title dialog') +}) + for (const [lang, dict] of [ ['fr', fr], ['en', en], diff --git a/apps/app/src/components/ui/Dialog.tsx b/apps/app/src/components/ui/Dialog.tsx index 8a351b38..34c1828b 100644 --- a/apps/app/src/components/ui/Dialog.tsx +++ b/apps/app/src/components/ui/Dialog.tsx @@ -30,8 +30,23 @@ const SIZE: Record, string> = { xl: 'max-w-4xl', } -/** The title; `outline-none`: only a script focuses it (`titleId`), never a key. */ -const TITLE = 'text-lg font-semibold text-[var(--color-ink)] outline-none' +/** + * The title; `outline-none`: only a script focuses it (`titleId`), never a key. A long + * one wraps (`min-w-0 break-words`) and never pushes the ✕ out. + */ +const TITLE = + 'min-w-0 break-words text-lg font-semibold text-[var(--color-ink)] outline-none' + +/** The ✕'s 44 px box sets the header's height: its padding stays small. */ +const HEADER = + 'flex items-center justify-between gap-2 border-b border-[var(--color-border)] ' + + 'py-1 pl-4 pr-1 sm:py-2 sm:pl-6 sm:pr-3' + +/** The ✕: a 44 × 44 px touch box, as MobileDrawer's close (Rev 6). */ +const CLOSE = + 'grid h-11 w-11 shrink-0 place-items-center rounded-lg ' + + 'text-[var(--color-ink-muted)] hover:bg-[var(--color-surface-strong)] ' + + 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]' export default function Dialog({ open, ...surface }: DialogProps) { return ( @@ -79,7 +94,7 @@ function DialogSurface({ transition={{ duration: reduced ? 0 : 0.18 }} className={`relative w-full ${SIZE[size]} max-h-[85vh] overflow-y-auto overscroll-contain rounded-2xl bg-[var(--color-surface)] shadow-xl`} > -
+

✕ diff --git a/apps/app/tests/unit/ui.Dialog.test.tsx b/apps/app/tests/unit/ui.Dialog.test.tsx index 7bd73f67..647fb553 100644 --- a/apps/app/tests/unit/ui.Dialog.test.tsx +++ b/apps/app/tests/unit/ui.Dialog.test.tsx @@ -56,6 +56,31 @@ describe('Dialog', () => { expect(dialog).toHaveAccessibleDescription('It goes for good.') }) + it('its ✕ is a 44 px box with a visible focus ring; a long title wraps beside it (Rev 6)', () => { + useLocaleStore.setState({ locale: 'fr' }) + render( + {}} title="X"> + body + , + ) + const close = screen.getByRole('button', { name: 'Fermer' }) + for (const name of [ + 'grid', + 'h-11', + 'w-11', + 'shrink-0', + 'place-items-center', + 'rounded-lg', + 'focus-visible:ring-2', + ]) { + expect(close).toHaveClass(name) + } + expect(screen.getByRole('heading', { name: 'X' })).toHaveClass( + 'min-w-0', + 'break-words', + ) + }) + it('has no description when none is given', () => { render( {}} title="X">