Skip to content

Commit dc66d33

Browse files
feat(plugin-form): the form dialog maximizes in place like the record drawer, remembered per object (#34703)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBU5y97XtBcJ8qSLSR3B3Djd)_ Fixes #34604 Clause-②: no Metadata-protocol: none repo:objectstack#3 · os-support-ai · session_01WGufzgwLiKcfujYUug7sPs ## 维护者速读 - 改了什么:新建 / 编辑表单弹窗的标题栏加了放大 / 还原按钮(和记录抽屉同一个图标、同一个位置,紧挨关闭按钮左边);普通表单和带行项目的表单两种弹窗都有,并按对象记住上次的选择。 - 为什么改:长表单、带行项目的报价单在弹窗里只能用 90% 高度、受限宽度;维护者要求「展开为整页,现在右侧弹出框已经有放大缩小的图标,可以统一风格」。 - 风险与回滚:只改弹窗外框的 class,表单本身不重新挂载,已填内容、未保存提示、行项目都保留;回滚即还原本 PR,选择记录在浏览器 localStorage(键 `modal-form-maximized:OBJECT`),无数据或元数据改动。 - 先看:`ui/packages/plugin-form/src/ModalForm.tsx`(`effectiveModalSize` 里的放大覆盖、`heightClass`、`maximizeButton`)、`ui/packages/plugin-form/src/modalMaximize.ts`(按对象记忆)、`__tests__/modalMaximize-34604.test.tsx`。 - 两分钟验证:控制台打开「新建商机」,填两个字段后点标题栏右上角关闭按钮左边的放大图标:弹窗铺满、内容还在;再点还原回原尺寸;关掉重开同一对象仍是放大状态,换一个对象是原尺寸。 - 需要你做的:无,席位落地。 ## What changes - The form dialog (`ModalForm`) draws the record drawer's maximize / restore switch in its header: the same `RecordTopBarButton`, the lucide `Maximize2` / `Minimize2` pair at `h-3.5 w-3.5`, the same existing i18n keys (`detail.maximize` / `detail.restoreSize`), placed just before the close (X) button in both position and tab order. Both arms carry it: the flat form and the `subforms` master-detail form (its own `MobileDialogContent`). - Maximized, the effective size is `full` (`sm:max-w-[95vw]`) whatever the authored or inferred size, and the height cap is lifted: `sm:h-auto sm:max-h-[90vh]` becomes `sm:h-[95dvh] sm:max-h-[95dvh]`, so the dialog fills the window and its body scroller (not the page) scrolls a long form. Restore puts back the exact previous classes. - Toggling changes the content element's classes only. The form subtree is not remounted: typed values, the dirty state that arms the discard guard, and master-detail lines all survive (pinned by element identity). - Every reader of the size reads the effective size, so `dialogUndeclaredColumns(fieldCount, modalSize)` (#34607) answers four columns for a 16+-field undeclared form when maximized, and three again when restored. - The choice is a per-object preference (ui AGENTS.md #8): a new package-internal helper `modalMaximize.ts` stores `modal-form-maximized:OBJECT` in `localStorage` (try/catch, SSR-safe; restore removes the entry). It is re-read when a mounted dialog is handed another object. Not re-exported from `index.tsx` or `core.ts`. - Phone: the sheet already fills the screen, so the switch is drawn from `sm` up only (`hidden sm:inline-flex`). The header gets `sm:pr-20` so a long title stays clear of the two buttons. - Clause-② `no` holds: no new locale key (the two keys exist in every pack; only the no-provider English defaults table in `ModalForm` gains the two entries the drawer's table carries), no new export or prop on `@object-ui/plugin-form` or `@object-ui/components`, no spec key. `mobile-dialog-content.tsx` is untouched (the override merges over its base `sm:max-h-[90vh]`). - Kept: #34599's close guard and sticky Save bar in the master-detail arm (pinned maximized: the discard prompt still fires on the X, `md-form-submit` still drawn); #34607's `dialogUndeclaredColumns`. ## Tests New file `ui/packages/plugin-form/src/__tests__/modalMaximize-34604.test.tsx` (10 tests; no shared ModalForm harness file exists, so a card-named file): - flat arm: label/aria and icon, order before Close, `sm`-only, same content node across toggles, restore gives back the previous width class; typed value and same input element across two toggles, then the X still opens "Discard changes?"; switch present with `modalCloseButton: false`. - preference: reopen maximized for the same object, another object unaffected; restore forgets; a mounted dialog handed another object takes that object's choice; a throwing `Storage` leaves the switch working. - columns: 16 undeclared fields read three per row at `@4xl` in the inferred `xl`, four maximized, three restored; the typed value survives. - master-detail arm: switch present and toggles the same content node; header value and an added line (same input elements) survive two toggles, Save bar drawn, the X still prompts. No existing pin changed (`dialogDefaultLayout-12521`, `modalViewportGutter-12593`, `modalCloseButton-11061`, `ObjectForm.mobileFullscreen` all pass unchanged). <details><summary>Readings at head ea132c4</summary> - `pnpm --dir ui exec vitest run --maxWorkers=2 packages/plugin-form/src/__tests__/modalMaximize-34604.test.tsx`: Test Files 1 passed, Tests 10 passed; lock VERDICT command-exit 0. - `pnpm --dir ui exec vitest run --maxWorkers=2 packages/plugin-form/`: Test Files 235 passed (235), Tests 2628 passed, 1 skipped (2629); lock VERDICT command-exit 0. - `pnpm --filter @object-ui/plugin-form type-check` (`tsc --noEmit && tsc -p tsconfig.test.json`): exit 0; `--listFiles` of `tsconfig.test.json` lists the new test file. </details> <details><summary>Ablations (one-shot, restored, no permanent test files)</summary> Both through `scripts/ablation-replace.mjs` (anchor 1 to 0, blob moved, restore verified blob == HEAD and `git diff HEAD` empty). The test imports `../ModalForm` from source, so no build sits on the path. 1. `if (maximized) return 'full';` replaced by a constant-false guard: 10 of 10 tests red. 2. `key={maximized ? 'max' : 'restored'}` added to the flat arm's content (a remount on toggle): the two flat-arm identity tests red ("expected the same dialog node", "expected the same input element"), 1 passed. </details> ## Acceptance notes - Before: the form dialog had no size control; the inferred size stops at `xl` and the height at `90vh`. After: the switch above, in both arms, remembered per object. - Escape still runs the close guard while maximized (the drawer's Escape restores first); not asked by the card, left as is. - An authored `modalSize: 'full'` still shows the switch: there maximize only lifts the height cap. - ui AGENTS.md #2 (README / `content/docs/frontend`) was not updated: neither page describes the dialog's runtime chrome today and both are outside this card's file surface. - Overlaps #34642 in ModalForm.tsx; whichever lands second merges main. (`overlap-check`: origin/main merges cleanly; #34642 conflicts in `ui/packages/plugin-form/src/ModalForm.tsx`, exit 1.) ## Verification <details><summary>Local gates (derived by `dispatch-gates.mjs --commands`, reconciled with `--ran`)</summary> - 38 derived commands, 38 run, each exit 0 (`--ran` verdict: "38 run, 0 NOT-MEASURED (a DERIVED zero — all 38 recorded an exit code and none of them is 3)"). - `pnpm check:new-line-citations` (ui): 0 new citations, exit 0. - Families CI runs (Test UI, Type Check UI, Lint UI, Build and E2E UI, the rest) are read from this PR's check-runs, not re-run locally. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufzgwLiKcfujYUug7sPs)_ <!-- signed: repo:objectstack#3 · os-support-ai · session_01WGufzgwLiKcfujYUug7sPs --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent e47c1cb commit dc66d33

4 files changed

Lines changed: 543 additions & 6 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
'@object-ui/plugin-form': patch
3+
---
4+
5+
feat(plugin-form): the form dialog's header has a maximize / restore button, like the record drawer's, and remembers the choice per object
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A create or edit dialog could not be made bigger: a long form, or a form with line items, stayed in a dialog capped at 90% of the window height. The dialog header now has the record drawer's maximize button (the same icon, size and labels, "Maximize" / "Restore size"), just before the close (X) button.
11+
12+
- **Maximize** widens the dialog to the `full` size (95% of the window width) and makes it fill 95% of the window height. The form body scrolls inside the dialog.
13+
- **Restore size** puts the dialog back to its declared or inferred size.
14+
- The form stays open the whole time. Typed values, the unsaved-changes prompt on close, and line items added in a form with `subforms` are all kept.
15+
- Both dialog kinds have the button: a plain form and a form with `subforms` (line items).
16+
- A maximized dialog with no declared `columns` uses the `full` column count, so a form with sixteen or more fields shows four per row.
17+
- The choice is remembered per object in the browser's local storage. The next dialog for that object opens the same way. Other objects are not affected.
18+
- On a phone the dialog already fills the screen, so the button is shown from the `sm` breakpoint up only.
19+
20+
No metadata changes. An authored `modalSize` is still the size the dialog opens with until the user maximizes it.

‎ui/packages/plugin-form/src/ModalForm.tsx‎

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ import {
3333
AlertDialogDescription,
3434
AlertDialogAction,
3535
AlertDialogCancel,
36+
RecordTopBarButton,
3637
toast,
3738
FormSectionNavContext,
3839
} from '@object-ui/components';
39-
import { Loader2 } from 'lucide-react';
40+
import { Loader2, Maximize2, Minimize2 } from 'lucide-react';
4041
import { MasterDetailForm } from './MasterDetailForm';
4142
import { SchemaRenderer, useSafeFieldLabel, usePreviewMode } from '@object-ui/react';
4243
import { createSafeTranslation, useLocalization } from '@object-ui/i18n';
@@ -88,6 +89,7 @@ import { useUploadGate, UploadGateProvider, UploadInFlightNotice } from './uploa
8889
import { useInitialFieldFocus } from './initialFieldFocus';
8990
import { FormSectionNav, useFormSectionNav } from './FormSectionNav';
9091
import { FormDirtyReportContext } from './formDirtyReport';
92+
import { useModalFormMaximized } from './modalMaximize';
9193

9294
// Localized strings for the unsaved-changes guard and, since objectui#11039,
9395
// the form's own chrome (the default submit and cancel labels and the
@@ -118,6 +120,10 @@ const useDiscardTranslation = createSafeTranslation(
118120
// The heading of the fields no declared field group claims
119121
// (`deriveFieldGroupSections`' trailing bucket).
120122
'common.ungroupedSection': 'Other',
123+
// The header's maximize / restore switch: the record drawer's own pair of
124+
// keys and labels (objectstack-ai/objectstack#34604).
125+
'detail.maximize': 'Maximize',
126+
'detail.restoreSize': 'Restore size',
121127
},
122128
'form.discardTitle',
123129
);
@@ -511,6 +517,12 @@ const ModalFormBody: React.FC<ModalFormProps> = ({
511517
? effectiveSections.reduce((n, s) => n + (Array.isArray(s.fields) ? s.fields.length : 0), 0)
512518
: layoutPool.length;
513519

520+
// The header's maximize switch (objectstack-ai/objectstack#34604):
521+
// maximized, the dialog is `full` whatever its authored or inferred size,
522+
// and every reader of the size below — the width class and the undeclared
523+
// column count — reads that effective size.
524+
const { maximized, toggleMaximized } = useModalFormMaximized(schema.objectName);
525+
514526
// The dialog's size when the author declared none (objectui#12521): bounded
515527
// — `lg` or `xl`, never `full` — and chosen from the declared grid and the
516528
// field count, so a short form is not stretched across a wide dialog. An
@@ -519,12 +531,13 @@ const ModalFormBody: React.FC<ModalFormProps> = ({
519531
// size, so the size reads that floor and never the count it then bounds
520532
// (objectstack-ai/objectstack#34607).
521533
const effectiveModalSize = useMemo(() => {
534+
if (maximized) return 'full';
522535
if (schema.modalSize) return schema.modalSize;
523536
const columns = effectiveSections?.length
524537
? sectionedFormColumns(schema.columns, effectiveSections.map((s) => s.columns), DIALOG_DEFAULT_COLUMNS)
525538
: (clampColumns(schema.columns) ?? DIALOG_DEFAULT_COLUMNS);
526539
return inferModalSize(Math.min(columns, inferColumns(layoutFieldCount)));
527-
}, [schema.modalSize, schema.columns, effectiveSections, layoutFieldCount]);
540+
}, [maximized, schema.modalSize, schema.columns, effectiveSections, layoutFieldCount]);
528541

529542
// The count an undeclared form or section draws in THIS dialog
530543
// (objectstack-ai/objectstack#34607): from the field count, bounded by the
@@ -542,6 +555,13 @@ const ModalFormBody: React.FC<ModalFormProps> = ({
542555
}, [formFields, objectSchema, flatColumns, schema.mode, effectiveSections]);
543556

544557
const sizeClass = modalSizeClasses[effectiveModalSize] || modalSizeClasses.default;
558+
// The content's height: a phone sheet is always the whole screen; from `sm`
559+
// up the dialog grows with its body to a `90vh` cap, and maximized it fills
560+
// `95dvh` — the height counterpart of the `full` size's `95vw` — so its body
561+
// scroller, not the page, scrolls a long form.
562+
const heightClass = maximized
563+
? 'h-[100dvh] sm:h-[95dvh] sm:max-h-[95dvh]'
564+
: 'h-[100dvh] sm:h-auto sm:max-h-[90vh]';
545565

546566
// Fetch object schema
547567
useEffect(() => {
@@ -1226,6 +1246,28 @@ const ModalFormBody: React.FC<ModalFormProps> = ({
12261246
attemptClose(false);
12271247
};
12281248

1249+
// The header's maximize / restore switch (objectstack-ai/objectstack#34604):
1250+
// the record drawer's control — its `RecordTopBarButton`, its lucide pair at
1251+
// its size, its labels — drawn just before the dialog's close (X), in both
1252+
// arms. The last child of the content, so it sits after the form in the tab
1253+
// order and right before the X, as the drawer orders them. From `sm` up
1254+
// only: the phone sheet already fills the screen. Toggling changes the
1255+
// content's classes and nothing else, so the form below stays mounted.
1256+
const maximizeButton = (
1257+
<RecordTopBarButton
1258+
label={maximized ? t('detail.restoreSize') : t('detail.maximize')}
1259+
onClick={toggleMaximized}
1260+
data-testid="modal-form-maximize"
1261+
className={cn('absolute top-2.5 hidden sm:inline-flex', showCloseButton ? 'right-9' : 'right-3')}
1262+
>
1263+
{maximized ? <Minimize2 className="h-3.5 w-3.5" /> : <Maximize2 className="h-3.5 w-3.5" />}
1264+
</RecordTopBarButton>
1265+
);
1266+
// The header keeps its title clear of the switch and the X from `sm` up.
1267+
// Its bottom rule is each arm's: the flat arm hands it to the section nav
1268+
// strip when one is drawn.
1269+
const headerClass = 'shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 sm:pr-20 pb-2';
1270+
12291271
// Unsaved-changes guard — rendered INSIDE DialogContent so its portal
12301272
// inherits the Dialog's Radix layer context (focus scope + dismissable
12311273
// layer) through React. As a sibling of <Dialog> it had no such context, so
@@ -1265,10 +1307,11 @@ const ModalFormBody: React.FC<ModalFormProps> = ({
12651307
showCloseButton={showCloseButton}
12661308
onOpenAutoFocus={initialFieldFocus.onOpenAutoFocus}
12671309
onCloseAutoFocus={initialFieldFocus.onCloseAutoFocus}
1268-
className={cn(sizeClass, 'flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0', className, schema.className)}
1310+
className={cn(sizeClass, 'flex flex-col overflow-hidden p-0', heightClass, className, schema.className)}
1311+
data-maximized={maximized ? '' : undefined}
12691312
>
12701313
{(schema.title || schema.description) && (
1271-
<DialogHeader className="shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b">
1314+
<DialogHeader className={cn(headerClass, 'border-b')}>
12721315
{schema.title && <DialogTitle>{schema.title}</DialogTitle>}
12731316
{schema.description ? (
12741317
<DialogDescription>{schema.description}</DialogDescription>
@@ -1319,6 +1362,7 @@ const ModalFormBody: React.FC<ModalFormProps> = ({
13191362
</Suspense>
13201363
</div>
13211364
{discardDialog}
1365+
{maximizeButton}
13221366
</MobileDialogContent>
13231367
</Dialog>
13241368
);
@@ -1332,10 +1376,11 @@ const ModalFormBody: React.FC<ModalFormProps> = ({
13321376
showCloseButton={showCloseButton}
13331377
onOpenAutoFocus={initialFieldFocus.onOpenAutoFocus}
13341378
onCloseAutoFocus={initialFieldFocus.onCloseAutoFocus}
1335-
className={cn(sizeClass, 'flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0', className, schema.className)}
1379+
className={cn(sizeClass, 'flex flex-col overflow-hidden p-0', heightClass, className, schema.className)}
1380+
data-maximized={maximized ? '' : undefined}
13361381
>
13371382
{(schema.title || schema.description) && (
1338-
<DialogHeader className={cn('shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2', !drawsSectionNav && 'border-b')}>
1383+
<DialogHeader className={cn(headerClass, !drawsSectionNav && 'border-b')}>
13391384
{schema.title && <DialogTitle>{schema.title}</DialogTitle>}
13401385
{schema.description ? (
13411386
<DialogDescription>{schema.description}</DialogDescription>
@@ -1416,6 +1461,7 @@ const ModalFormBody: React.FC<ModalFormProps> = ({
14161461
the Dialog content the conflict alert stacks as the topmost Radix
14171462
layer, so its buttons receive clicks while the modal stays open. */}
14181463
{conflictDialog}
1464+
{maximizeButton}
14191465
</MobileDialogContent>
14201466
</Dialog>
14211467
);

0 commit comments

Comments
 (0)