feat(editor): dialog close button is a 44 px touch box

This commit is contained in:
bchanot committed 2026-11-15 19:40:46 +01:00
1 parent ae02f48853
commit 240c2ba0e7
4 files changed
+79 -5

No files matched your search

+10 -1
View File
@@ -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 }) {
<div className="flex flex-wrap gap-2">
<Button onClick={() => onOpen('basic')}>Open basic</Button>
<Button onClick={() => onOpen('long')}>Open long</Button>
<Button onClick={() => onOpen('title')}>Open wrapped title</Button>
<Button onClick={() => onOpen('guarded')}>Open guarded</Button>
</div>
<Button variant="secondary" onClick={() => setClicks((n) => n + 1)}>
@@ -88,6 +93,10 @@ function Harness() {
<Button onClick={close}>End of content</Button>
</Dialog>
<Dialog open={scenario === 'title'} onClose={close} title={LONG_TITLE}>
<Button onClick={close}>Done</Button>
</Dialog>
<Dialog
open={scenario === 'guarded'}
onClose={() => !busy && close()}
+25
View File
@@ -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],
+19 -4
View File
@@ -30,8 +30,23 @@ const SIZE: Record<NonNullable<DialogProps['size']>, 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`}
>
<header className="flex items-center justify-between px-4 sm:px-6 py-3 sm:py-4 border-b border-[var(--color-border)]">
<header className={HEADER}>
<h2
id={titleId ?? ownTitleId}
tabIndex={titleId ? -1 : undefined}
@@ -91,7 +106,7 @@ function DialogSurface({
type="button"
aria-label={t('common.close')}
onClick={onClose}
className="rounded-md p-1 text-[var(--color-ink-muted)] hover:bg-[var(--color-surface-strong)]"
className={CLOSE}
>
✕
</button>
+25
View File
@@ -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(
<Dialog open onClose={() => {}} title="X">
body
</Dialog>,
)
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(
<Dialog open onClose={() => {}} title="X">