Skip to content

Commit 276ca30

Browse files
fix(components): give the Dialog close button a 44 px touch target at phone width (#29204)
domain:ui#2 · zhuangjianguo · session_01QsR2jRFuJz9QBZqPVHYVhJ <!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Steedos** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbCP1P1FEnhJ4Bx9RmczEwBK)_ Fixes #29107 Clause-②: no Metadata-protocol: none ## 维护者速读 - **改了什么**:手机宽度(小于 sm 断点)下,所有弹窗右上角的关闭按钮从 16×16 px 的点击区扩大到 44×44 px,图标本身仍是 16 px;桌面宽度下按钮样式一字未改。 - **为什么改**:移动端 App 用 WebView 承载 Console,手机用户打开的每个弹窗(操作参数弹窗如审批「驳回」、命令面板 ⌘K 等)都用这一个共享 Dialog,关闭按钮太小、经常点不中。 - **风险与回滚**:只加了 `max-sm:` 前缀的样式类,桌面不受影响;图标在手机上向内移动 2 px(距角 17 px → 19 px)。回滚即 revert 本 PR。 - **先看**:`ui/scripts/shadcn-local-patches.mjs`(新增的 `phoneCloseTouchTargetPatches` 补丁声明)、`ui/packages/components/src/ui/dialog.tsx`(Close 那一行)、`ui/packages/components/src/__tests__/dialog-close-touch-target-29107.test.tsx`。 - **两分钟验证**:`pnpm --dir ui exec vitest run packages/components/src/__tests__/dialog-close-touch-target-29107.test.tsx scripts/__tests__/shadcn-local-patches.test.ts`,预期全绿;或在 375 px 宽的 Console 里按 Ctrl+K,关闭按钮的点击区是 44×44。 - **需要你做的**:无,席位落地。 ## What changes - The close button `DialogContent` draws in its top-right corner gets a phone-only touch target: below `sm` it is a 44 x 44 px flex box placed 4 px from the corner with the 16 px glyph centred (`max-sm:right-1 max-sm:top-1 max-sm:flex max-sm:size-11 max-sm:items-center max-sm:justify-center`, the class set #29078 uses for the Sheet close). From `sm` up the class list is upstream's, token for token, so the desktop header does not grow. - `dialog.tsx` is a Shadcn-synced file (`ui/AGENTS.md` commandment 7), so the change is declared as a local patch, `phoneCloseTouchTargetPatches('Dialog')` in `ui/scripts/shadcn-local-patches.mjs`, anchored on the opening of the Close element's class list as the vendored registry fixture spells it. The shipped `dialog.tsx` line was written by applying that patch to the file, so `REGISTRY_FIXTURES.dialog` keeps its byte round trip (`roundTrip: true`) and the next `pnpm shadcn:update` re-applies it instead of reverting it. The helper takes the Radix prefix, so the Sheet close can take the same family. - Both sites the card names render `DialogContent`'s own close: the declared-action param dialog (`ActionParamDialog`, e.g. the `sys_approval_request` Reject decision) and the command palette (`CommandDialog`). - `ui/packages/components/shadcn-components.json`: dialog's `localEdits` note now names the phone close touch-target patch beside the i18n close patch (claim amendment 6573487904). - Changeset `.changeset/29107-dialog-close-phone-touch-target.md`: `@object-ui/components` patch. ## Tests - New `ui/packages/components/src/__tests__/dialog-close-touch-target-29107.test.tsx`: on `DialogContent` and on `CommandDialog`, the Close carries the six phone classes, every class without the `max-sm:` prefix equals upstream's list in order, and the glyph keeps `h-4 w-4`. - `ui/scripts/__tests__/shadcn-local-patches.test.ts`: the dialog declares the new patch id; applied to the registry bytes it adds the phone classes and leaves upstream's Close classes unchanged; it refuses (only that patch, the close-label family still lands) when upstream moves the Close off `right-4 top-4`. The two close-label counts on dialog are scoped to their own family. - Ablation, one-shot, at 20e48bf: with `dialog.tsx` restored to main's bytes (tree only, restored from HEAD afterwards, `git status` clean), 4 cases go red: both new component cases, "dialog.tsx carries its declared patches" and "dialog: byte round-trip holds". ## Acceptance notes - The glyph moves 2 px on phones: it sat 17 px from the dialog's top-right edge (16 px placement plus the 1 px border) and now sits 19 px (4 px placement + 1 px border + 14 px centring inside 44 px). That is the cost of matching #29078's class set; `max-sm:right-0.5 max-sm:top-0.5` would keep it at 17 px. - The 2 px glyph shift above is accepted by the seat: it keeps the Dialog and Sheet class sets identical. - `sheet.tsx`'s close is #29078's; `REGISTRY_FIXTURES.sheet` is `roundTrip: true` as well, so a bare class edit there reds "sheet: byte round-trip holds" unless it is declared the same way. ## Verification - Real browser, showcase backend plus the Console Vite dev server, Playwright at 375 x 812 and 1280 x 800, measuring the dialog element's own Close (screenshots and the script stay in the project files, not here): - Before (main's `dialog.tsx`): param dialog and command palette Close are 16 x 16 px at 375 px and at 1280 px. - After: 44 x 44 px at 375 px on both sites, glyph 16 x 16; at 1280 px both are still 16 x 16 px at the same position. - Local gates at 20e48bf: the 36 families `dispatch-gates --commands` derives for this diff all exit 0 (`--ran` reconciliation: 36 derived, 36 run, 0 NOT-MEASURED), including `node scripts/check-sdui-manifest.mjs` and `pnpm --dir ui exec vitest run scripts/` (169 files, 4903 tests passed). `@object-ui/components` type-check (including `tsconfig.test.json`) exit 0; eslint on the four touched source files exit 0; `pnpm check:new-line-citations` 0 new. - After merging main (d0c0add, no main commit touches these files): the three touched test files re-run green (66 tests). - At cc550d3 (the `localEdits` note): the same 36 derived families; the files that read `shadcn-components.json` plus the patch and dialog tests re-run green (5 files, 92 tests), `check:published-files`, `check:nul-bytes` and `check-empty-changeset` exit 0. - At 1855aa3: `snapshot-critical.test.tsx` ("Dialog snapshots > renders open dialog structure", red in Test UI 10/16 on cc550d3) regenerated with `vitest --update`; the `.snap` diff is the Close line only, gaining the six `max-sm:` classes. A sweep of every `*.snap`, `*.test.*` and `*.spec.*` file for the Close class list (`right-4 top-4 rounded-sm`, `rounded-sm opacity-70`, `data-[state=open]:bg-accent data-[state=open]:text-muted-foreground`) finds no other pin. The snapshot file and the dialog test re-run green (2 files, 22 tests); the whole components package did not finish locally within 560 s, so CI Test UI carries it. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. --- _Generated by [Claude Code](https://claude.ai/code/session_01QsR2jQryAdPcJnhAWQzVjB)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 5cdaf9a commit 276ca30

7 files changed

Lines changed: 225 additions & 6 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@object-ui/components': patch
3+
---
4+
5+
fix(components): the shared Dialog close button is a 44 px touch target at phone width
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
Below the `sm` breakpoint the close button that `DialogContent` draws in its top-right corner was the bare 16 px glyph, a 16 x 16 px tap target. It is now a 44 x 44 px box with the 16 px glyph centred in it, 4 px from the corner. From `sm` up its classes are unchanged, so desktop dialogs look and measure as before. Every dialog built on `DialogContent` gets it, including the action parameter dialog and the command palette. `dialog.tsx` is a Shadcn-synced file, so the change is declared in `ui/scripts/shadcn-local-patches.mjs` and re-applied on every `pnpm shadcn:update`.

‎ui/packages/components/shadcn-components.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
"radix-ui"
132132
],
133133
"registryDependencies": [],
134-
"localEdits": "objectstack#5505 i18n close patch: `DialogContent` auto-renders an icon-only close button whose `sr-only` span IS its accessible name, and upstream hardcodes the English literal — so under zh/ja/es every modal in the console announced \"Close\" in English. The span is replaced by `<CloseSrLabel />` (`packages/components/src/lib/close-label.tsx`), which resolves `common.close` for the session locale and falls back to English with no I18nProvider mounted. The edit is DECLARED as data in `scripts/shadcn-local-patches.mjs` and re-applied on every `--update`, and `pnpm shadcn:check` exits non-zero if it is ever missing from the file or can no longer be re-applied to upstream."
134+
"localEdits": "objectstack#5505 i18n close patch: `DialogContent` auto-renders an icon-only close button whose `sr-only` span IS its accessible name, and upstream hardcodes the English literal — so under zh/ja/es every modal in the console announced \"Close\" in English. The span is replaced by `<CloseSrLabel />` (`packages/components/src/lib/close-label.tsx`), which resolves `common.close` for the session locale and falls back to English with no I18nProvider mounted. It also carries the objectstack#29107 phone close touch-target patch: below `sm` the close button is a 44 px box with the 16 px glyph centred, and from `sm` up its classes are upstream's. Both edits are DECLARED as data in `scripts/shadcn-local-patches.mjs` and re-applied on every `--update`, and `pnpm shadcn:check` exits non-zero if either is ever missing from the file or can no longer be re-applied to upstream."
135135
},
136136
"drawer": {
137137
"source": "https://ui.shadcn.com/r/styles/default/drawer.json",

‎ui/packages/components/src/__tests__/__snapshots__/snapshot-critical.test.tsx.snap‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ exports[`Dialog snapshots > renders open dialog structure 1`] = `
492492
</button>
493493
</div>
494494
<button
495-
class="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground"
495+
class="absolute right-4 top-4 max-sm:right-1 max-sm:top-1 max-sm:flex max-sm:size-11 max-sm:items-center max-sm:justify-center rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground"
496496
type="button"
497497
>
498498
<svg
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* objectstack#29107 — the shared `Dialog` Close button is a 44 px touch target
11+
* at phone width.
12+
*
13+
* Every modal the Console shows draws the one close button `DialogContent`
14+
* auto-renders, so the floor lives in the primitive. Two sites render it and
15+
* are named here: the declared-action param dialog (`ActionParamDialog` in
16+
* `@object-ui/app-shell`, e.g. a `sys_approval_request` Reject) and the
17+
* command palette (`CommandDialog`, rendered below).
18+
*
19+
* The test environment has no layout engine, so the target is pinned as
20+
* drawn: a 44 px centred box below `sm`, and from `sm` up the class list the
21+
* desktop had before, token for token. `src/ui/dialog.tsx` is regenerated from
22+
* the registry; the classes are a declared patch in
23+
* `scripts/shadcn-local-patches.mjs`, whose own test proves the anchor.
24+
*/
25+
26+
import { describe, it, expect, afterEach } from 'vitest';
27+
import { render, screen, cleanup } from '@testing-library/react';
28+
import { Dialog, DialogContent, DialogTitle, DialogDescription } from '../ui/dialog';
29+
import { CommandDialog, CommandInput, CommandList } from '../ui/command';
30+
31+
afterEach(() => cleanup());
32+
33+
/** The phone-only classes `phoneCloseTouchTargetPatches` declares. */
34+
const PHONE = [
35+
'max-sm:size-11',
36+
'max-sm:flex',
37+
'max-sm:items-center',
38+
'max-sm:justify-center',
39+
'max-sm:right-1',
40+
'max-sm:top-1',
41+
];
42+
43+
/** Upstream's class list for the Close, unchanged from `sm` up. */
44+
const DESKTOP = [
45+
'absolute',
46+
'right-4',
47+
'top-4',
48+
'rounded-sm',
49+
'opacity-70',
50+
'ring-offset-background',
51+
'transition-opacity',
52+
'hover:opacity-100',
53+
'focus:outline-none',
54+
'focus:ring-2',
55+
'focus:ring-ring',
56+
'focus:ring-offset-2',
57+
'disabled:pointer-events-none',
58+
'data-[state=open]:bg-accent',
59+
'data-[state=open]:text-muted-foreground',
60+
];
61+
62+
function expectPhoneTarget(close: HTMLElement) {
63+
const cls = close.className.split(/\s+/).filter(Boolean);
64+
for (const c of PHONE) expect(cls).toContain(c);
65+
// Every phone class is `max-sm:` scoped, and nothing else was added, so the
66+
// desktop button (and the header around it) is exactly what it was.
67+
expect(cls.filter((c) => !c.startsWith('max-sm:'))).toEqual(DESKTOP);
68+
// The visible glyph keeps its 16 px size.
69+
expect(close.querySelector('svg')?.getAttribute('class')).toContain('h-4 w-4');
70+
}
71+
72+
describe('#29107 — the Dialog Close button on a phone', () => {
73+
it('DialogContent: a 44 px box below sm, upstream classes from sm up', () => {
74+
render(
75+
<Dialog open>
76+
<DialogContent>
77+
<DialogTitle>Reject</DialogTitle>
78+
<DialogDescription>Declared-action param dialog</DialogDescription>
79+
</DialogContent>
80+
</Dialog>,
81+
);
82+
expectPhoneTarget(screen.getByRole('button', { name: 'Close' }));
83+
});
84+
85+
it('the command palette draws the same Close', () => {
86+
render(
87+
<CommandDialog open>
88+
<CommandInput placeholder="Search" />
89+
<CommandList />
90+
</CommandDialog>,
91+
);
92+
expectPhoneTarget(screen.getByRole('button', { name: 'Close' }));
93+
});
94+
});

‎ui/packages/components/src/ui/dialog.tsx‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎ui/scripts/__tests__/shadcn-local-patches.test.ts‎

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,67 @@ describe('shadcn local patches — application to fresh upstream (objectstack#55
358358
]);
359359
});
360360

361+
/**
362+
* The sixth family: the dialog Close's phone touch target (objectstack#29107).
363+
* One patch; the classes are `max-sm:` scoped, so the desktop button keeps
364+
* upstream's class list untouched.
365+
*/
366+
it('dialog declares the phone close touch-target patch', () => {
367+
const ids = LOCAL_PATCHES.dialog
368+
.filter((p: { issue: string }) => p.issue === 'objectstack#29107')
369+
.map((p: { id: string }) => p.id);
370+
expect(ids).toEqual(['dialog-phone-close-touch-target']);
371+
});
372+
373+
it('gives the upstream dialog Close a 44 px phone box and leaves its desktop classes alone', () => {
374+
const result = applyLocalPatches('dialog', UPSTREAM_DIALOG);
375+
expect(result.failed).toEqual([]);
376+
377+
const closeTag = (src: string) => {
378+
const m = src.match(/<DialogPrimitive\.Close className="([^"]*)">/);
379+
expect(m, 'no DialogPrimitive.Close class list found').not.toBeNull();
380+
return m![1].split(/\s+/).filter(Boolean);
381+
};
382+
const before = closeTag(UPSTREAM_DIALOG);
383+
const after = closeTag(result.content);
384+
385+
for (const c of [
386+
'max-sm:size-11',
387+
'max-sm:flex',
388+
'max-sm:items-center',
389+
'max-sm:justify-center',
390+
'max-sm:right-1',
391+
'max-sm:top-1',
392+
]) {
393+
expect(after).toContain(c);
394+
}
395+
// Every added class is phone-scoped; the rest is upstream, token for token.
396+
expect(after.filter((c) => !c.startsWith('max-sm:'))).toEqual(before);
397+
// The glyph keeps its 16 px size.
398+
expect(result.content).toContain('<X className="h-4 w-4" />');
399+
});
400+
401+
it('refuses when upstream moves the dialog Close off its corner placement', () => {
402+
// The anchor names the Close's opening class list. If upstream re-places
403+
// the button, the phone box would be computed against a corner that no
404+
// longer exists, so the family must refuse rather than land somewhere new.
405+
const moved = UPSTREAM_DIALOG.replace(
406+
'<DialogPrimitive.Close className="absolute right-4 top-4 ',
407+
'<DialogPrimitive.Close className="absolute right-3 top-3 ',
408+
);
409+
expect(moved).not.toBe(UPSTREAM_DIALOG);
410+
411+
const result = applyLocalPatches('dialog', moved);
412+
413+
expect(result.failed.map((p: { id: string }) => p.id)).toEqual([
414+
'dialog-phone-close-touch-target',
415+
]);
416+
expect(result.failed[0].found).toBe(0);
417+
// The close-label family is independent of the class list and still lands.
418+
expect(result.applied).toHaveLength(2);
419+
expect(result.content).not.toContain('max-sm:size-11');
420+
});
421+
361422
it('applies the slider family to fresh upstream, and is idempotent', () => {
362423
const once = applyLocalPatches('slider', UPSTREAM_SLIDER);
363424

@@ -444,7 +505,11 @@ describe('shadcn local patches — application to fresh upstream (objectstack#55
444505
const result = applyLocalPatches('dialog', UPSTREAM_DIALOG);
445506

446507
expect(result.failed).toEqual([]);
447-
expect(result.applied).toHaveLength(2);
508+
// Scoped to the close-label family: dialog carries a second family since
509+
// objectstack#29107 (the phone close touch target), asserted on its own.
510+
expect(
511+
result.applied.filter((p: { issue: string }) => p.issue === 'objectstack#5505'),
512+
).toHaveLength(2);
448513
// The English literal is GONE — this is the actual user-visible defect.
449514
expect(result.content).not.toContain('<span className="sr-only">Close</span>');
450515
expect(result.content).toContain('<CloseSrLabel />');
@@ -459,7 +524,7 @@ describe('shadcn local patches — application to fresh upstream (objectstack#55
459524

460525
expect(twice.content).toBe(once.content);
461526
expect(twice.applied).toEqual([]);
462-
expect(twice.already).toHaveLength(2);
527+
expect(twice.already).toHaveLength(LOCAL_PATCHES.dialog.length);
463528
expect(twice.failed).toEqual([]);
464529
});
465530

‎ui/scripts/shadcn-local-patches.mjs‎

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,14 +648,64 @@ const calendarDisplayLocalePatches = [
648648
},
649649
];
650650

651+
/** The phone-only classes the close-touch-target family adds (objectstack#29107). */
652+
const PHONE_CLOSE_TOUCH_TARGET =
653+
'max-sm:right-1 max-sm:top-1 max-sm:flex max-sm:size-11 max-sm:items-center max-sm:justify-center';
654+
655+
/**
656+
* The phone-width close-button touch-target patch (objectstack#29107).
657+
*
658+
* `DialogContent` auto-renders its close button as the bare 16 px lucide glyph
659+
* inside `absolute right-4 top-4`, with no padding and no minimum size, so on a
660+
* phone the whole tap target is 16 x 16 px — under the 44 px floor the
661+
* Console's phone-width audit holds every control to. Every modal a phone user
662+
* opens draws this one button (the declared-action param dialog, the command
663+
* palette), so the floor belongs in the primitive, not at each call site.
664+
*
665+
* The payload is phone-only (`max-sm:`), so from `sm` up the button keeps
666+
* upstream's classes and the desktop header does not grow. Below `sm` the
667+
* button becomes a 44 px flex box anchored 4 px from the corner, the glyph
668+
* centred in it at its own 16 px size. The Sheet close takes the same class
669+
* set through its own family, `sheetCloseTouchTargetPatches`.
670+
*
671+
* Inline, like the `hideOverlay` family: the payload is utility classes on the
672+
* primitive's own element, so there is no implementation to host in `src/lib/`.
673+
* One anchor, written from the vendored registry bytes
674+
* (`scripts/__tests__/fixtures/shadcn-registry/dialog.registry.txt`): the
675+
* opening of the Close element's class list, which names the element and its
676+
* desktop placement and nothing incidental. The phone classes sit right after
677+
* the placement they override.
678+
*
679+
* @param {string} primitive Radix namespace prefix, e.g. `Dialog`.
680+
* @returns {LocalPatch[]}
681+
*/
682+
function phoneCloseTouchTargetPatches(primitive) {
683+
const anchor = `<${primitive}Primitive.Close className="absolute right-4 top-4 `;
684+
return [
685+
{
686+
id: `${primitive.toLowerCase()}-phone-close-touch-target`,
687+
issue: 'objectstack#29107',
688+
reason:
689+
`${primitive}Content's close button is a 16 x 16 px tap target upstream ` +
690+
'(the bare glyph, no padding or minimum size). Below `sm` this makes it a ' +
691+
'44 px box with the glyph centred; from `sm` up upstream classes apply ' +
692+
'unchanged, so the desktop header does not grow.',
693+
find: anchor,
694+
replace: `${anchor}${PHONE_CLOSE_TOUCH_TARGET} `,
695+
marker: `${anchor}${PHONE_CLOSE_TOUCH_TARGET} `,
696+
occurrences: 1,
697+
},
698+
];
699+
}
700+
651701
/**
652702
* Component name (as tracked in `shadcn-components.json`) → patches it needs.
653703
*
654704
* @type {Record<string, LocalPatch[]>}
655705
*/
656706
export const LOCAL_PATCHES = {
657707
sheet: [...i18nCloseLabelPatches('Sheet'), ...sheetHideOverlayPatches, ...sheetCloseTouchTargetPatches],
658-
dialog: i18nCloseLabelPatches('Dialog'),
708+
dialog: [...i18nCloseLabelPatches('Dialog'), ...phoneCloseTouchTargetPatches('Dialog')],
659709
sidebar: [
660710
...sidebarCookieReadPatches,
661711
...sidebarOptionalContextPatches,

0 commit comments

Comments
 (0)