From 9749feeb9074761e81ccc414c159370db019bbe9 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 03:49:25 +0000 Subject: [PATCH 1/4] feat(plugin-form): an undeclared dialog grid follows the field count, three wide when bounded, four in a full dialog Claude-Session: https://claude.ai/code/session_01WGufzgwLiKcfujYUug7sPs Co-authored-by: Claude --- ui/packages/plugin-form/src/ModalForm.tsx | 129 +++++++++++++--------- ui/packages/plugin-form/src/autoLayout.ts | 61 ++++++++-- 2 files changed, 131 insertions(+), 59 deletions(-) diff --git a/ui/packages/plugin-form/src/ModalForm.tsx b/ui/packages/plugin-form/src/ModalForm.tsx index c3f4baf8592..d7aba688ec0 100644 --- a/ui/packages/plugin-form/src/ModalForm.tsx +++ b/ui/packages/plugin-form/src/ModalForm.tsx @@ -49,6 +49,7 @@ import { filterSystemFields, inferColumns, inferModalSize, + dialogUndeclaredColumns, sectionedFormColumns, sectionedGridLayout, CONTAINER_GRID_COLS, @@ -310,25 +311,30 @@ const modalSizeClasses: Record = { }; /** - * How many fields per row the dialog draws where the author declared no - * `columns` (objectui#12521): two from the container's `@md` tier up, one - * below it, so the phone sheet keeps its single column. It rides the spec's - * own `columns` / `colSpan` path, so every field takes one cell — fields of - * one kind share one width — while a wide kind (`isWideFieldType`: textarea, - * rich text, markdown, html, an inline `grid`) and a `span: 'full'` field take - * the whole row. Line items never reach this grid: they arrive as `subforms`, - * which the master-detail arm below lays out across the dialog. + * The least grid the dialog draws where the author declared no `columns` + * (objectui#12521): two from the container's `@md` tier up, one below it, so + * the phone sheet keeps its single column. A field-heavy form draws more — + * three in a bounded dialog, four in a `full` one — by + * `dialogUndeclaredColumns` (objectstack-ai/objectstack#34607), whose + * docblock carries the rule and the measured tier. * - * It applies to a flat form with no `columns`. A SECTION that declares no - * `columns` — the object's `fieldGroups` among them — gets the same count - * through the one sectioned-form rule, `sectionedGridLayout` - * (`UNDECLARED_SECTION_COLUMNS`), which every page host shares - * (objectui#12592): an undeclared section density is the renderer's choice, - * and a declared one — `1` included — is drawn as written (the - * section-`columns` fork on objectui#12521, ruled 6204264665). + * Every undeclared count rides the spec's own `columns` / `colSpan` path, so + * every field takes one cell — fields of one kind share one width — while a + * wide kind (`isWideFieldType`: textarea, rich text, markdown, html, an inline + * `grid`) and a `span: 'full'` field take the whole row. Line items never + * reach this grid: they arrive as `subforms`, which the master-detail arm + * below lays out across the dialog. * - * The flat default is dialog-only on purpose: a flat page form, a drawer and - * the detail view keep `inferColumns`, which they mirror between them. + * It applies to a flat form with no `columns`, and to a SECTION that declares + * no `columns` — the object's `fieldGroups` among them — through the one + * sectioned-form rule, `sectionedGridLayout`, handed the dialog's count: an + * undeclared section density is the renderer's choice, and a declared one — + * `1` included — is drawn as written (the section-`columns` fork on + * objectui#12521, ruled 6204264665). + * + * The count is dialog-only on purpose: a sectioned page form keeps + * `UNDECLARED_SECTION_COLUMNS`, and a flat page form, a drawer and the detail + * view keep `inferColumns`, which they mirror between them. */ const DIALOG_DEFAULT_COLUMNS = UNDECLARED_SECTION_COLUMNS; @@ -461,55 +467,71 @@ const ModalFormBody: React.FC = ({ [schema.sections, schema.objectName, schema.formType, objectSchema, dataSource], ); + // The fields a flat or field-group layout draws: system fields dropped, and + // in create mode the server-computed ones too — what `applyAutoLayout` + // filters (it filters again; the filters are idempotent). `customFields` is + // already merged into `formFields` (objectui#10073). + const layoutPool = useMemo(() => { + const fs = filterSystemFields(formFields, objectSchema); + return schema.mode === 'create' ? filterAutoGeneratedFields(fs, objectSchema) : fs; + }, [formFields, objectSchema, schema.mode]); + // Field-group fallback (object-designer metadata): when the caller passes no // explicit sections, honor the object's declared `fieldGroups` the same way // ObjectForm's simple path does — one section per group, with flat-path // auto-layout parity (system/auto-generated fields filtered, the dialog's - // default columns, wide fields spanning the row). An explicit curated - // `sections` list from a form view always wins over this fallback. + // undeclared count, wide fields spanning the row). An explicit curated + // `sections` list from a form view always wins over this fallback. The + // groups carry no `columns` of their own: the arm that draws them reads the + // form's declared count, else the dialog's (objectstack-ai/objectstack#34607). const derivedSections = useMemo(() => { // `customFields` does NOT switch the fallback off (objectui#10073): the // members are merged into `formFields` above, and ObjectForm derives its // groups over that same merged pool. if (schema.sections?.length) return null; - let fs = filterSystemFields(formFields, objectSchema); - if (schema.mode === 'create') fs = filterAutoGeneratedFields(fs, objectSchema); - const sections = deriveFieldGroupSections(fs, (objectSchema as any)?.fieldGroups, ungroupedLabel); - if (!sections) return null; - const columns = (clampColumns(schema.columns) ?? DIALOG_DEFAULT_COLUMNS) as 1 | 2 | 3 | 4; + const sections = deriveFieldGroupSections(layoutPool, (objectSchema as any)?.fieldGroups, ungroupedLabel); // A member's definition reaches a group's body through `buildSectionFields`, // the route an explicit section's takes (objectui#10254). - return sections.map((s) => ({ ...s, columns })) as ModalFormSectionConfig[]; - }, [schema.sections, schema.columns, schema.mode, formFields, objectSchema, ungroupedLabel]); + return sections ? (sections as ModalFormSectionConfig[]) : null; + }, [schema.sections, layoutPool, objectSchema, ungroupedLabel]); const effectiveSections = resolvedSections?.length ? resolvedSections : (derivedSections ?? undefined); - // Compute auto-layout for flat fields (no sections) to determine inferred columns - // (`customFields` does not switch it off: the members are merged into - // `formFields`, and ObjectForm auto-lays-out that merged list — objectui#10073.) - // A form that declares no `columns` lays out at the dialog's default - // (objectui#12521) through the same explicit-columns route an authored - // `columns` takes, so `applyAutoLayout` never infers 3–4 columns here. - const flatColumns = schema.columns ?? DIALOG_DEFAULT_COLUMNS; - const autoLayoutResult = useMemo(() => { - if (effectiveSections?.length) return null; - return applyAutoLayout(formFields, objectSchema, flatColumns, schema.mode); - }, [formFields, objectSchema, flatColumns, schema.mode, effectiveSections]); + // How many fields the dialog lays out — the input to its size and to its + // undeclared column count. + const layoutFieldCount = effectiveSections?.length + ? effectiveSections.reduce((n, s) => n + (Array.isArray(s.fields) ? s.fields.length : 0), 0) + : layoutPool.length; // The dialog's size when the author declared none (objectui#12521): bounded - // — `lg` or `xl`, never `full` — and chosen from the grid that renders and - // the field count, so a short form is not stretched across a wide dialog. - // An authored `modalSize` (including `'full'`) is used as written. + // — `lg` or `xl`, never `full` — and chosen from the declared grid and the + // field count, so a short form is not stretched across a wide dialog. An + // authored `modalSize` (including `'full'`) is used as written. An + // undeclared grid is at least `DIALOG_DEFAULT_COLUMNS` wide whatever the + // size, so the size reads that floor and never the count it then bounds + // (objectstack-ai/objectstack#34607). const effectiveModalSize = useMemo(() => { if (schema.modalSize) return schema.modalSize; const columns = effectiveSections?.length - ? sectionedFormColumns(schema.columns, effectiveSections.map((s) => s.columns)) - : (autoLayoutResult?.columns ?? DIALOG_DEFAULT_COLUMNS); - const fieldCount = effectiveSections?.length - ? effectiveSections.reduce((n, s) => n + (Array.isArray(s.fields) ? s.fields.length : 0), 0) - : (autoLayoutResult?.fields.length ?? 0); - return inferModalSize(Math.min(columns, inferColumns(fieldCount))); - }, [schema.modalSize, schema.columns, autoLayoutResult, effectiveSections]); + ? sectionedFormColumns(schema.columns, effectiveSections.map((s) => s.columns), DIALOG_DEFAULT_COLUMNS) + : (clampColumns(schema.columns) ?? DIALOG_DEFAULT_COLUMNS); + return inferModalSize(Math.min(columns, inferColumns(layoutFieldCount))); + }, [schema.modalSize, schema.columns, effectiveSections, layoutFieldCount]); + + // The count an undeclared form or section draws in THIS dialog + // (objectstack-ai/objectstack#34607): from the field count, bounded by the + // dialog's size — `dialogUndeclaredColumns`. + const undeclaredColumns = dialogUndeclaredColumns(layoutFieldCount, effectiveModalSize); + + // Compute auto-layout for flat fields (no sections). A form that declares no + // `columns` lays out at the dialog's undeclared count through the same + // explicit-columns route an authored `columns` takes, so `applyAutoLayout` + // never runs the page's inference here. + const flatColumns = schema.columns ?? undeclaredColumns; + const autoLayoutResult = useMemo(() => { + if (effectiveSections?.length) return null; + return applyAutoLayout(formFields, objectSchema, flatColumns, schema.mode); + }, [formFields, objectSchema, flatColumns, schema.mode, effectiveSections]); const sizeClass = modalSizeClasses[effectiveModalSize] || modalSizeClasses.default; @@ -964,13 +986,18 @@ const ModalFormBody: React.FC = ({ sec.name ? sectionLabel(schema.objectName, sec.name, sec.label || sec.name) : sec.label; // The form is ONE grid. Its width is the explicit form `columns`, else the - // widest section's count, an undeclared section counting two - // (objectui#12521, #12592); each section then lays ITS fields out at its + // widest section's count, an undeclared section counting the dialog's + // undeclared count (objectui#12521, #12592; objectstack-ai/objectstack#34607); + // each section then lays ITS fields out at its // own count within that grid via colSpan (objectstack-ai/objectstack#2578), exactly like the // full-page sectioned form — by the one sectioned-form rule, which // switches to a 12-track grid when the sections' counts do not all fit // the widest one (objectui#12548). It is handed the AUTHORED counts. - const sectionGrid = sectionedGridLayout(schema.columns, sections.map((sec) => sec.columns)); + const sectionGrid = sectionedGridLayout( + schema.columns, + sections.map((sec) => sec.columns), + undeclaredColumns, + ); const formColumns = sectionGrid.columns; const containerFieldClass = sectionGrid.fieldContainerClass; @@ -1083,7 +1110,7 @@ const ModalFormBody: React.FC = ({ // DrawerForm), so every group's fields share a single react-hook-form // instance and the footer submit collects them all. if (derivedSections?.length) { - const columns = (Number(derivedSections[0]?.columns) || 1) as 1 | 2 | 3 | 4; + const columns = (clampColumns(schema.columns) ?? undeclaredColumns) as 1 | 2 | 3 | 4; const allFields: FormField[] = []; derivedSections.forEach((section, index) => { // FLS first, so a group whose every field is non-readable drops its diff --git a/ui/packages/plugin-form/src/autoLayout.ts b/ui/packages/plugin-form/src/autoLayout.ts index 3e9f1a83f87..6c11ba90453 100644 --- a/ui/packages/plugin-form/src/autoLayout.ts +++ b/ui/packages/plugin-form/src/autoLayout.ts @@ -375,10 +375,15 @@ function declaredColumns(n: unknown): number | undefined { /** * One section's fields per row: its declared `columns` as written, else the * form's declared `columns` (what an undeclared section always filled), else - * {@link UNDECLARED_SECTION_COLUMNS}. + * `undeclared` — {@link UNDECLARED_SECTION_COLUMNS} on every page host; the + * dialog passes its own count ({@link dialogUndeclaredColumns}). */ -export function sectionColumnsFor(sectionColumns: unknown, formColumns: unknown): number { - return declaredColumns(sectionColumns) ?? declaredColumns(formColumns) ?? UNDECLARED_SECTION_COLUMNS; +export function sectionColumnsFor( + sectionColumns: unknown, + formColumns: unknown, + undeclared: number = UNDECLARED_SECTION_COLUMNS, +): number { + return declaredColumns(sectionColumns) ?? declaredColumns(formColumns) ?? undeclared; } /** @@ -387,14 +392,16 @@ export function sectionColumnsFor(sectionColumns: unknown, formColumns: unknown) * * @param formColumns The form's DECLARED `columns` (`undefined` when none). * @param sectionColumns The DECLARED `columns` of every section the form draws. + * @param undeclared The count an undeclared section draws (see {@link sectionColumnsFor}). */ export function sectionedFormColumns( formColumns: unknown, sectionColumns: ReadonlyArray, + undeclared: number = UNDECLARED_SECTION_COLUMNS, ): 1 | 2 | 3 | 4 { const widest = sectionColumns.length - ? Math.max(...sectionColumns.map((c) => sectionColumnsFor(c, formColumns))) - : UNDECLARED_SECTION_COLUMNS; + ? Math.max(...sectionColumns.map((c) => sectionColumnsFor(c, formColumns, undeclared))) + : undeclared; return (declaredColumns(formColumns) ?? widest) as 1 | 2 | 3 | 4; } @@ -439,18 +446,22 @@ export interface SectionedGridLayout { * (objectui#12592): an undeclared section and an undeclared form resolve here, * through {@link sectionColumnsFor} and {@link sectionedFormColumns}, so a * section that declares nothing draws {@link UNDECLARED_SECTION_COLUMNS} per - * row in the dialog and on every page host alike. + * row on every page host. The dialog alone passes `undeclared` — its own + * count for a field-heavy form ({@link dialogUndeclaredColumns}) — and every + * page host leaves it at the default, so their output is what it was. * * @param formColumns The form's DECLARED `columns` (`undefined` when none). * @param sectionColumns The DECLARED `columns` of every section the form draws. + * @param undeclared The count an undeclared section draws (see {@link sectionColumnsFor}). */ export function sectionedGridLayout( formColumns: unknown, sectionColumns: ReadonlyArray, + undeclared: number = UNDECLARED_SECTION_COLUMNS, ): SectionedGridLayout { - const grid = sectionedFormColumns(formColumns, sectionColumns); + const grid = sectionedFormColumns(formColumns, sectionColumns, undeclared); const density = (declared: unknown) => - Math.min(sectionColumnsFor(declared, formColumns), grid); + Math.min(sectionColumnsFor(declared, formColumns, undeclared), grid); const fits = sectionColumns.every((c) => { const d = density(c); return d === 1 || d === grid; @@ -538,6 +549,40 @@ export function inferModalSize(columns: number): 'sm' | 'default' | 'lg' | 'xl' return 'xl'; } +/** + * How many fields per row a DIALOG draws where its author declared no + * `columns` — on the form, and for a section on that section too + * (objectstack-ai/objectstack#34607). Dialog-only: every page host keeps + * {@link UNDECLARED_SECTION_COLUMNS} for a section and {@link inferColumns} + * for a flat form. + * + * The count is {@link inferColumns} of the fields the dialog lays out, so a + * field-heavy business form spreads across a wide dialog while a light one is + * never thinned out — with two bounds: + * + * - FLOOR two: the dialog's earlier fixed default (objectui#12521), so a form + * of up to eight fields draws exactly what it drew before. + * - CAP by the dialog's size: three in a bounded dialog, four only in a + * `full` one. The grid's tiers are container queries + * ({@link CONTAINER_GRID_COLS}), and the bounded `xl` dialog's field + * container already reaches the `@4xl` tier (`sm:max-w-5xl` is 64rem, less + * the scroller's `sm:px-6` leaves 61rem, over `@4xl`'s 56rem), so a + * four-wide grid would draw four columns there. A bounded dialog stops at + * three; the fourth column is the `full` dialog's. + * + * Below the container's `@md` tier every count draws one column, so the + * phone sheet keeps its single column. A declared `columns` — `1` included — + * never reaches this function: it is drawn as written (the section-`columns` + * fork on objectui#12521, ruled 6204264665). + * + * @param fieldCount The number of fields the dialog lays out. + * @param modalSize The dialog's effective size (authored or inferred). + */ +export function dialogUndeclaredColumns(fieldCount: number, modalSize: string): 2 | 3 | 4 { + const cap = modalSize === 'full' ? 4 : 3; + return Math.min(Math.max(UNDECLARED_SECTION_COLUMNS, inferColumns(fieldCount)), cap) as 2 | 3 | 4; +} + /** * Main auto-layout orchestrator. * Applies intelligent defaults only when the user has not explicitly configured layout. From 00954afa7dd46e933f9406445ece5b8454cf0ad7 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 04:10:22 +0000 Subject: [PATCH 2/4] test(plugin-form): pin the dialog's undeclared count and move the 12521/12592 dialog pins to it Claude-Session: https://claude.ai/code/session_01WGufzgwLiKcfujYUug7sPs Co-authored-by: Claude --- .../dialogContainerColumns-34607.test.tsx | 254 ++++++++++++++++++ .../dialogDefaultLayout-12521.test.tsx | 36 ++- .../undeclaredSectionDensity-12592.test.tsx | 12 +- 3 files changed, 289 insertions(+), 13 deletions(-) create mode 100644 ui/packages/plugin-form/src/__tests__/dialogContainerColumns-34607.test.tsx diff --git a/ui/packages/plugin-form/src/__tests__/dialogContainerColumns-34607.test.tsx b/ui/packages/plugin-form/src/__tests__/dialogContainerColumns-34607.test.tsx new file mode 100644 index 00000000000..e9d90ab6569 --- /dev/null +++ b/ui/packages/plugin-form/src/__tests__/dialogContainerColumns-34607.test.tsx @@ -0,0 +1,254 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/** + * objectstack-ai/objectstack#34607 — a dialog whose author declared no + * `columns` spreads a field-heavy form across its width: three per row in a + * bounded dialog, four in a `full` one, one on a phone. A declared `columns` + * is drawn as written, and every page host draws what it drew before. + * + * The count is `dialogUndeclaredColumns` (`autoLayout.ts`): `inferColumns` of + * the fields laid out, at least two (the dialog's earlier default, + * objectui#12521), at most three unless the dialog is `full`. The bounded + * `xl` dialog's field container reaches the `@4xl` tier (64rem less the + * scroller's 3rem of padding is 61rem, over 56rem), so the cap — not the + * container — is what keeps a bounded dialog at three. + * + * jsdom evaluates no container query, so a count per row is read from the + * classes the real form renderer draws: at each tier, the grid tracks in force + * over the field's span in force (the reading `undeclaredSectionDensity-12592` + * uses). + */ + +import React from 'react'; +import { describe, it, expect, vi, afterEach } from 'vitest'; +import { render, waitFor, cleanup } from '@testing-library/react'; +import { registerAllFields } from '@object-ui/fields'; +import '@object-ui/components'; +import { ModalForm } from '../ModalForm'; +import { ObjectForm } from '../ObjectForm'; +import { + dialogUndeclaredColumns, + sectionedGridLayout, + UNDECLARED_SECTION_COLUMNS, +} from '../autoLayout'; + +registerAllFields(); + +afterEach(() => cleanup()); + +const PLAIN = Array.from({ length: 14 }, (_, i) => `f${i}`); + +/** Sixteen fields, no layout declared: fourteen plain ones, a textarea and a markdown body. */ +const SIXTEEN = { + name: 'thing', + fields: { + ...Object.fromEntries(PLAIN.map((n) => [n, { type: 'text', label: `Field ${n}` }])), + notes: { type: 'textarea', label: 'Notes' }, + body: { type: 'markdown', label: 'Body' }, + }, +}; + +/** Five plain fields: a light form. */ +const FIVE = { + name: 'thing', + fields: Object.fromEntries(PLAIN.slice(0, 5).map((n) => [n, { type: 'text', label: `Field ${n}` }])), +}; + +const ds = (def: unknown): any => ({ + getObjectSchema: vi.fn().mockResolvedValue(def), + findOne: vi.fn().mockResolvedValue({}), + find: vi.fn().mockResolvedValue({ data: [] }), + create: vi.fn(), + update: vi.fn(), +}); + +type Def = { fields: Record }; + +function schemaFor(def: Def, extra: Record) { + return { + type: 'object-form', + objectName: 'thing', + mode: 'create', + fields: Object.keys(def.fields), + ...extra, + } as any; +} + +async function settle(name: string) { + await waitFor(() => expect(document.body.querySelector(`[data-field="${name}"]`)).not.toBeNull()); +} + +async function openDialog(def: Def, extra: Record = {}) { + render(); + await settle('f0'); + return document.body.querySelector('[role="dialog"]') as HTMLElement; +} + +async function openPage(def: Def, extra: Record = {}) { + render(); + await settle('f0'); +} + +/** The grid classes of the container holding `name`, and that field's own span classes. */ +function readField(name: string): { grid: string[]; span: string[] } { + const cell = document.body.querySelector(`[data-field="${name}"]`); + if (!cell) throw new Error(`field not rendered: ${name}`); + const tokens = (el: Element | null) => (el?.getAttribute('class') || '').split(/\s+/).filter(Boolean); + return { + grid: tokens(cell.parentElement).filter((t) => /(^|:)grid-cols-/.test(t)), + span: tokens(cell).filter((t) => /(^|:)col-span-/.test(t)), + }; +} + +const TIERS = ['@md', '@2xl', '@4xl'] as const; + +/** Fields per row at a container tier: tracks in force / span in force (min-width prefixes). */ +function perRowAt(read: { grid: string[]; span: string[] }, tier: (typeof TIERS)[number]): number { + const upTo = TIERS.slice(0, TIERS.indexOf(tier) + 1); + const inForce = (list: string[], stem: string) => { + let v: number | undefined; + for (const t of upTo) { + const hit = list.find((c) => c.startsWith(`${t}:${stem}`)); + if (hit) v = Number(hit.split('-').pop()); + } + return v; + }; + return (inForce(read.grid, 'grid-cols-') ?? 1) / (inForce(read.span, 'col-span-') ?? 1); +} + +/** Per row at `@md` / `@2xl` / `@4xl`. */ +const ladder = (name: string) => { + const read = readField(name); + return TIERS.map((t) => perRowAt(read, t)); +}; + +/** Below `@md`: only unprefixed `grid-cols-*` classes apply. */ +const belowMd = (name: string) => readField(name).grid.filter((t) => !t.includes(':')); + +const TWO_SECTIONS = [ + { name: 'a', label: 'A', fields: PLAIN.slice(0, 8) }, + { name: 'b', label: 'B', fields: [...PLAIN.slice(8), 'notes', 'body'] }, +]; + +describe('#34607 acceptance 1 — sixteen undeclared fields: three in an xl dialog, four in a full one, one on a phone', () => { + it('the inferred dialog is the bounded xl, and draws three per row from @2xl, never four', async () => { + const dialog = await openDialog(SIXTEEN); + expect(dialog.className).toContain('sm:max-w-5xl'); + expect(ladder('f0')).toEqual([2, 3, 3]); + }); + + it("the full dialog (an authored modalSize: 'full') reaches four per row at @4xl", async () => { + const dialog = await openDialog(SIXTEEN, { modalSize: 'full' }); + expect(dialog.className).toContain('sm:max-w-[95vw]'); + expect(ladder('f0')).toEqual([2, 3, 4]); + }); + + it('below @md the grid is one column, in either size', async () => { + await openDialog(SIXTEEN); + expect(belowMd('f0')).toEqual(['grid-cols-1']); + expect(readField('f0').span.filter((t) => !t.includes(':'))).toEqual([]); + cleanup(); + await openDialog(SIXTEEN, { modalSize: 'full' }); + expect(belowMd('f0')).toEqual(['grid-cols-1']); + }); + + it('item 3 — the wide kinds take the whole row at every tier, four-wide grid included', async () => { + await openDialog(SIXTEEN, { modalSize: 'full' }); + expect(ladder('notes')).toEqual([1, 1, 1]); + expect(ladder('body')).toEqual([1, 1, 1]); + }); +}); + +describe('#34607 acceptance 2 — a declared columns is drawn as written', () => { + it('a declared columns: 2 stays two per row, in xl and in full', async () => { + await openDialog(SIXTEEN, { columns: 2 }); + expect(ladder('f0')).toEqual([2, 2, 2]); + cleanup(); + await openDialog(SIXTEEN, { columns: 2, modalSize: 'full' }); + expect(ladder('f0')).toEqual([2, 2, 2]); + }); + + it('a declared columns: 1 stays one per row', async () => { + await openDialog(SIXTEEN, { columns: 1 }); + expect(ladder('f0')).toEqual([1, 1, 1]); + }); + + it('a section declaring columns: 2 keeps two beside an undeclared section that draws three', async () => { + await openDialog(SIXTEEN, { + sections: [{ ...TWO_SECTIONS[0], columns: 2 }, TWO_SECTIONS[1]], + }); + expect(ladder('f0')).toEqual([2, 2, 2]); + expect(ladder('f8')).toEqual([2, 3, 3]); + }); +}); + +describe('#34607 — undeclared sections and field groups in the dialog take the same count', () => { + it('undeclared sections: three per row in xl, four in full', async () => { + await openDialog(SIXTEEN, { sections: TWO_SECTIONS }); + expect(ladder('f0')).toEqual([2, 3, 3]); + expect(ladder('notes')).toEqual([1, 1, 1]); + cleanup(); + await openDialog(SIXTEEN, { sections: TWO_SECTIONS, modalSize: 'full' }); + expect(ladder('f0')).toEqual([2, 3, 4]); + }); + + it("the object's fieldGroups with no layout: three per row in xl", async () => { + const grouped = { + ...SIXTEEN, + fieldGroups: [ + { key: 'main', label: 'Main' }, + { key: 'more', label: 'More' }, + ], + fields: Object.fromEntries( + Object.entries(SIXTEEN.fields).map(([k, f], i) => [k, { ...f, group: i < 8 ? 'main' : 'more' }]), + ), + }; + await openDialog(grouped); + expect(ladder('f0')).toEqual([2, 3, 3]); + expect(ladder('notes')).toEqual([1, 1, 1]); + }); + + it('a light form keeps the two-wide floor in the same xl dialog', async () => { + const dialog = await openDialog(FIVE); + expect(dialog.className).toContain('sm:max-w-5xl'); + expect(ladder('f0')).toEqual([2, 2, 2]); + }); +}); + +describe('#34607 CONTROL — the page hosts draw what they drew before', () => { + it('ObjectForm sectioned, every section undeclared: still two per row (UNDECLARED_SECTION_COLUMNS)', async () => { + await openPage(SIXTEEN, { sections: TWO_SECTIONS }); + expect(ladder('f0')).toEqual([2, 2, 2]); + expect(belowMd('f0')).toEqual(['grid-cols-1']); + }); + + it("ObjectForm flat: still the page's own inference (sixteen fields → four, on the renderer's viewport grid)", async () => { + await openPage(SIXTEEN); + expect(readField('f0').grid).toEqual(['md:grid-cols-2', 'lg:grid-cols-3', 'xl:grid-cols-4']); + }); + + it('sectionedGridLayout with no third argument is the shared rule the page hosts call', () => { + expect(UNDECLARED_SECTION_COLUMNS).toBe(2); + const shared = sectionedGridLayout(undefined, [undefined, undefined]); + expect(shared.columns).toBe(2); + expect(shared.fieldContainerClass).toBe('grid gap-4 grid-cols-1 @md:grid-cols-2'); + const mixed = sectionedGridLayout(undefined, [undefined, 3]); + expect(mixed.columns).toBe(3); + expect(mixed.fieldContainerClass).toBe('grid gap-4 grid-cols-1 @md:grid-cols-12'); + }); +}); + +describe('#34607 dialogUndeclaredColumns', () => { + it('floors at two, follows inferColumns, caps at three unless full', () => { + expect([1, 3, 8].map((n) => dialogUndeclaredColumns(n, 'xl'))).toEqual([2, 2, 2]); + expect([9, 15, 16, 40].map((n) => dialogUndeclaredColumns(n, 'xl'))).toEqual([3, 3, 3, 3]); + expect([9, 15, 16, 40].map((n) => dialogUndeclaredColumns(n, 'full'))).toEqual([3, 3, 4, 4]); + expect(dialogUndeclaredColumns(16, 'lg')).toBe(3); + }); +}); diff --git a/ui/packages/plugin-form/src/__tests__/dialogDefaultLayout-12521.test.tsx b/ui/packages/plugin-form/src/__tests__/dialogDefaultLayout-12521.test.tsx index 5b0f556ec02..d4f69b6937a 100644 --- a/ui/packages/plugin-form/src/__tests__/dialogDefaultLayout-12521.test.tsx +++ b/ui/packages/plugin-form/src/__tests__/dialogDefaultLayout-12521.test.tsx @@ -26,6 +26,16 @@ * row from `@md`, beside any other section's count, on objectui#12548's * per-section grid. A declared count, `1` included, is drawn as written. * + * ## Since objectstack-ai/objectstack#34607 + * + * The undeclared GRID is no longer a fixed two: a field-heavy form spreads + * to three per row in a bounded dialog and four in a `full` one + * (`dialogUndeclaredColumns`). Two stays the floor, so a form of up to eight + * fields still draws the pins below as written; the twelve-field fixture + * (`inferColumns` → three) now draws the three-wide grid, and its pins read + * that. The size, the phone column and every authored count are unchanged. + * The full #34607 matrix is `dialogContainerColumns-34607.test.tsx`. + * * ## What it reads * * The real `ModalForm` with the real form renderer and field registry, as @@ -118,24 +128,28 @@ async function openDialog(def: { fields: Record }, extra: Recor } const DEFAULT_GRID = 'grid gap-4 grid-cols-1 @md:grid-cols-2'; +/** The undeclared grid of a twelve-field form in a bounded dialog (objectstack-ai/objectstack#34607). */ +const THREE_GRID = 'grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3'; +/** A wide field's span on that grid: the whole row at every tier. */ +const WIDE_ON_THREE = ['@md:col-span-2', '@2xl:col-span-3']; /** objectui#12548's per-section grid, drawn when the sections' counts do not all fit one grid. */ const TWELVE_TRACK_GRID = 'grid gap-4 grid-cols-1 @md:grid-cols-12'; describe('a dialog with no authored layout (objectui#12521)', () => { - it('twelve fields: a bounded xl dialog, a two-column grid from @md, one cell per field, the textarea across the row', async () => { + it('twelve fields: a bounded xl dialog, a three-wide grid (two from @md, three from @2xl — #34607), one cell per field, the textarea across the row', async () => { const { dialog, grid, spanOf } = await openDialog(TWELVE); expect(dialog.className).toContain('sm:max-w-5xl'); expect(dialog.className).not.toContain('sm:max-w-[95vw]'); - expect(grid?.className).toBe(DEFAULT_GRID); + expect(grid?.className).toBe(THREE_GRID); // Fields of one kind share one width: every non-wide field is one cell. for (const name of Object.keys(TWELVE.fields).filter((n) => n !== 'notes')) { expect(spanOf(name), name).toEqual([]); } - // The wide kind spans both columns. - expect(spanOf('notes')).toEqual(['@md:col-span-2']); + // The wide kind spans the row at every tier. + expect(spanOf('notes')).toEqual(WIDE_ON_THREE); }); it('a short form gets the lg bound, not a dialog wider than its fields', async () => { @@ -149,13 +163,13 @@ describe('a dialog with no authored layout (objectui#12521)', () => { // Every multi-column tier is a container query from @md up; the base is one column. const tokens = (grid?.className ?? '').split(/\s+/); expect(tokens).toContain('grid-cols-1'); - expect(tokens.filter((t) => /grid-cols-(?!1$)/.test(t)).every((t) => t.startsWith('@md:'))).toBe(true); + expect(tokens.filter((t) => /grid-cols-(?!1$)/.test(t)).every((t) => t.startsWith('@'))).toBe(true); // The phone sheet's own classes are untouched. expect(dialog.className).toContain('h-[100dvh]'); expect(dialog.className).toContain('inset-0'); }); - it('object fieldGroups with no layout get the same two-column default', async () => { + it('object fieldGroups with no layout get the same undeclared grid as the flat form', async () => { const grouped = { ...TWELVE, fieldGroups: [ @@ -168,21 +182,21 @@ describe('a dialog with no authored layout (objectui#12521)', () => { }; const { dialog, grid, spanOf } = await openDialog(grouped); expect(dialog.className).toContain('sm:max-w-5xl'); - expect(grid?.className).toBe(DEFAULT_GRID); + expect(grid?.className).toBe(THREE_GRID); expect(spanOf('name')).toEqual([]); - expect(spanOf('notes')).toEqual(['@md:col-span-2']); + expect(spanOf('notes')).toEqual(WIDE_ON_THREE); }); - it('sections that declare no columns anywhere get the two-column default too', async () => { + it('sections that declare no columns anywhere get the same undeclared grid too', async () => { const { grid, spanOf } = await openDialog(TWELVE, { sections: [ { name: 'a', label: 'A', fields: ['name', 'code', 'email', 'phone', 'website', 'status'] }, { name: 'b', label: 'B', fields: ['stage', 'source', 'amount', 'quantity', 'due', 'notes'] }, ], }); - expect(grid?.className).toBe(DEFAULT_GRID); + expect(grid?.className).toBe(THREE_GRID); expect(spanOf('name')).toEqual([]); - expect(spanOf('notes')).toEqual(['@md:col-span-2']); + expect(spanOf('notes')).toEqual(WIDE_ON_THREE); }); }); diff --git a/ui/packages/plugin-form/src/__tests__/undeclaredSectionDensity-12592.test.tsx b/ui/packages/plugin-form/src/__tests__/undeclaredSectionDensity-12592.test.tsx index 0a358f155a3..f950ebfc37c 100644 --- a/ui/packages/plugin-form/src/__tests__/undeclaredSectionDensity-12592.test.tsx +++ b/ui/packages/plugin-form/src/__tests__/undeclaredSectionDensity-12592.test.tsx @@ -24,6 +24,12 @@ * These pins read the class attributes the real renderer draws, per host, and * compare each page host with the dialog, because the claim is about what * renders. + * + * objectstack-ai/objectstack#34607 parts the two for a field-heavy form: the + * dialog's undeclared count follows its field count (`dialogUndeclaredColumns`, + * at least two), while every page host keeps two. So the field-heavy + * `UNDECLARED` fixture now reads three per row from `@2xl` in the dialog and + * two on the page hosts; the light `MIXED` fixture still matches byte for byte. */ import React from 'react'; @@ -149,8 +155,10 @@ describe('objectui#12592 — an undeclared section draws as the dialog does, on expect(c1.grid, 'one column below @md').toContain('grid-cols-1'); expect(ladder(c1), '@md / @2xl / @4xl').toEqual([2, 2, 2]); expect(perRowAt(readField('full'), '@4xl'), "span: 'full' takes the row").toBe(1); - // Byte for byte the dialog's classes, not merely the same count. - expect(c1).toEqual(reference); + // The dialog spreads this field-heavy form to three from @2xl + // (objectstack-ai/objectstack#34607); the page host keeps two. + expect(reference.grid, 'dialog: one column below @md').toContain('grid-cols-1'); + expect(ladder(reference), 'dialog @md / @2xl / @4xl').toEqual([2, 3, 3]); }); it(`${host}: an undeclared section beside a declared columns: 3 one still draws two`, async () => { From 53e728b390870f57d99fa75631cc8ef3def610a4 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 04:19:20 +0000 Subject: [PATCH 3/4] chore(changeset): plugin-form dialog undeclared columns Claude-Session: https://claude.ai/code/session_01WGufzgwLiKcfujYUug7sPs Co-authored-by: Claude --- .changeset/34607-dialog-undeclared-columns.md | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .changeset/34607-dialog-undeclared-columns.md diff --git a/.changeset/34607-dialog-undeclared-columns.md b/.changeset/34607-dialog-undeclared-columns.md new file mode 100644 index 00000000000..736d2c234b4 --- /dev/null +++ b/.changeset/34607-dialog-undeclared-columns.md @@ -0,0 +1,20 @@ +--- +'@object-ui/plugin-form': patch +--- + +feat(plugin-form): a form dialog with no declared `columns` spreads a field-heavy form to three columns, and to four in a `full` dialog + +Clause-②: no +Metadata-protocol: none + +A record dialog whose form declares no `columns` drew every form two fields per row, however many fields it had. On a wide screen a long business form left most of the dialog empty. The dialog now picks its column count from the number of fields it shows: + +- **Up to eight fields:** two per row, as before. +- **Nine or more fields:** three per row, in the standard dialog sizes. +- **Sixteen or more fields in a `full` dialog** (`modalSize: 'full'`): four per row. + +The bounded `xl` dialog stops at three because its field area is already wider than the four-column breakpoint. Columns still follow the dialog's real width, so a narrow dialog and a phone show one column. Sections and the object's field groups that declare no `columns` get the same count. Long text, rich text, markdown, html and inline grid fields still take a whole row. + +A declared `columns`, including `1`, is drawn as written, on the form and on each section. The dialog's inferred size (`lg` or `xl`) is unchanged. Full-page, tabbed and wizard forms are unchanged: a section with no `columns` still draws two per row there. + +If your forms declare `columns: 2` only to keep the old dialog layout, you can remove it to get the wider layout. From 7ec78e2747fecaf0f64367e3249b0cdd3aa757d3 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 04:49:55 +0000 Subject: [PATCH 4/4] docs(plugin-form): the sectioned-form column section names the page default and the dialog's undeclared count Claude-Session: https://claude.ai/code/session_01WGufzgwLiKcfujYUug7sPs Co-authored-by: Claude --- ui/packages/plugin-form/README.md | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/ui/packages/plugin-form/README.md b/ui/packages/plugin-form/README.md index ecd7b659d76..ccc706983bb 100644 --- a/ui/packages/plugin-form/README.md +++ b/ui/packages/plugin-form/README.md @@ -542,11 +542,29 @@ A sectioned form renders as ONE grid, and two keys decide its shape: | a section's `columns` | how densely THAT section fills the grid (via per-field `colSpan`) | The view's `columns` wins; without it the grid takes the widest section's -density, and without either it is single-column. Every sectioned host resolves it -the same way — `ObjectForm` (simple), `ModalForm`, `TabbedForm`, `WizardForm` — -so one piece of metadata lays out identically wherever it is -rendered. (`WizardForm` has no widest-section fallback: its steps never share a -viewport, so each step keeps its own authored width.) +density. Every sectioned host resolves it through the same rule +(`sectionedGridLayout`) — `ObjectForm` (simple), `ModalForm`, `TabbedForm`, +`WizardForm`. (`WizardForm` has no widest-section fallback: its steps never share +a viewport, so each step keeps its own authored width.) + +A declared `columns` — on the view or on a section, `1` included — is drawn as +written on every host. Where neither the view nor a section declares one, the +count is the renderer's choice, and it differs by host: + +| Host | Undeclared count | +|---|---| +| page hosts (`ObjectForm`, `TabbedForm`, `WizardForm`) | 2 per row (`UNDECLARED_SECTION_COLUMNS`) | +| the form dialog (`ModalForm`) | by field count: 2 for up to eight fields, 3 from nine; 4 from sixteen in a `full` dialog (`dialogUndeclaredColumns`) | + +The dialog's count applies to a flat form, to undeclared sections and to the +object's `fieldGroups` alike. A bounded dialog (`lg` / `xl`) stops at 3 because +the `xl` dialog's field area already reaches the four-column container tier; +the fourth column is the `full` dialog's. + +Every count is a container-query grid, so it is an upper bound: the form draws +as many columns as its container is wide enough for, and one column below the +`@md` tier (a phone, a narrow drawer). Wide field kinds (textarea, rich text, +markdown, html, an inline `grid`) and `span: 'full'` fields take the whole row. The grid is applied to the field container **inside** the form, never wrapped around the `
` (which would put the whole form in cell 1 and leave the other