Repository navigation
Commit 2d05cd4
fix(ui): a form view's layout horizontal puts labels beside fields, and the form page draws tabbed views as tabs (#27222)
<!-- claude-projects-attribution: {"github_login":"os-warren"} -->
_Requested by **Warren** · [project
thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8XQi523WdBYxKuvgxjLJtnJ)_
Fixes #26843
Clause-②: no
Metadata-protocol: semantic
## 维护者速读
- 改了什么:表单视图写 `layout: 'horizontal'` 时,字段标签在 sm
及以上宽度放到输入框左侧(手机上仍是上下排);分页表单不再把它改回 vertical;`/forms/:name` 与 `/f/:slug`
表单页把 `type: 'tabbed'` 画成每节一个页签。
- 为什么改:这三项都能保存发布,但控制台画出来和没写一样,作者以为生效了其实没有(声明即生效)。
- 风险与回滚:只改字段的排布 class 与表单页的分节渲染;vertical 与不写 layout
的表单输出逐字节不变(有测试钉住);回滚即 revert 本 PR。
-
先看:`ui/apps/console/src/components/FormPage.tsx`(分页渲染与提交时跳到出错页签)、`ui/packages/components/src/renderers/form/form.tsx`(`HORIZONTAL_FIELD_ITEM_CLASS`)、`ui/packages/plugin-form/src/TabbedForm.tsx`。
- 两分钟验证:`pnpm --dir ui exec vitest run
apps/console/src/components/FormPage.tabbedLayout-26843.test.tsx`,预期 13
个测试全绿。
- 需要你做的:无,席位落地。
## What changes
1. **`layout: 'horizontal'` draws something.** The shared form renderer
(`@object-ui/components` `form`) used `layout` only to align its action
row. A horizontal field item is now a two-column grid from `sm` up: a
fixed label column (`minmax(0,10rem)`) and the control column, label on
the control's first text baseline. Every child except the `label` (the
control, its description, its message) is placed in the second column,
so a label-less field and the help text line up under the control. Every
class the arrangement adds is `sm:`-prefixed, so below `sm` the item is
the vertical one. `vertical` and an absent `layout` take the old code
path unchanged: same classes, same DOM. The label element, its `for` /
`id`, and the control's `aria-*` attributes are not touched.
2. **`TabbedForm` passes `layout` through.** It built its form node with
`layout: 'vertical'` whatever the form view said; it now forwards
`schema.layout` (declared on `TabbedFormSchema` as
`ObjectFormSchema['layout']`, the key `ObjectForm` already hands over in
its spread).
3. **The console form page draws `type: 'tabbed'`.** `FormPage`
(`/forms/:name`, `/f/:slug`) drew every section stacked. A tabbed form
view with more than one section now draws one tab per section with the
app's tabbed-form semantics: the tab key is the section's `name`, else
its heading, else its position (`TabbedForm`'s rule), `defaultTab` opens
first, `tabPosition` places the strip (top / bottom / left / right), a
section hidden by its `visibleWhen` draws no tab, and the panels are
force-mounted and CSS-hidden when closed. A submit carries every
section's fields from the page's one `values` map, closed tabs included;
a submit refused for a missing or faulted field opens the tab that holds
it. A one-section tabbed view draws stacked, as `TabbedForm` draws no
strip for one tab.
4. **In-place fix, same defect class: the form page's rows honour
`layout: 'horizontal'` too.** `FormPage` renders its own rows (not the
shared renderer) and never read `layout`, so after item 1 the form page
would have been the one entry point still ignoring it. Its rows take the
same arrangement (`HORIZONTAL_ROW_CLASS`). Same file as item 3, same
gate families.
Docs: the `layout` row in `ui/packages/plugin-form/README.md` and the
`FormSchema` block in `ui/content/docs/components/form/form.mdx` now say
what each value draws. The `object-form` registration's input help
already read "`horizontal` beside it" and is unchanged.
Changeset: `.changeset/26843-form-layout-horizontal-tabbed-page.md`,
`minor` for `@object-ui/components`, `@object-ui/plugin-form` and
`@object-ui/console`.
## Why
The card's rule is declared equals effective (ADR-0049): `layout:
'horizontal'` and `type: 'tabbed'` validate, save and publish, and the
console drew them exactly as if they were absent. PR #27027 made the
keys reach every console form entry point; this PR makes them draw.
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(`packages/spec` not touched.)
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes (ESLint on the changed
files: 0 errors; the repo-wide run is CI's).
- [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: n/a.
- [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, except the 维护者速读
section, which the dispatch order requires in Chinese.
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
## Tests
-
`ui/packages/components/src/renderers/form/__tests__/form-layout-horizontal-26843.test.tsx`
(5): the grid classes and the label as first child on a horizontal item;
every class horizontal adds is `sm:`-prefixed and none is removed
(stacked below `sm`); a label-less field keeps its control in column
two; the labels still name their controls (text, textarea, checkbox);
CONTROL: absent `layout` renders byte-identical to `vertical` (ids
normalised), and horizontal differs.
-
`ui/packages/plugin-form/src/__tests__/tabbedFormLayout-26843.test.tsx`
(3): a tabbed `ObjectForm` with `layout: 'horizontal'` draws both tabs'
fields horizontal; CONTROLS for no `layout` and `vertical`.
- `ui/apps/console/src/components/FormPage.tabbedLayout-26843.test.tsx`
(13): one tab per section named by its heading with every panel mounted;
`defaultTab`; tab click; `tabPosition: left` gives a vertical strip; a
submit carries `title`, `notes` and a never-opened tab's `defaults`
value; a refused submit opens the tab of the missing required field;
CONTROLS: one-section tabbed and `type: 'simple'` draw stacked with no
tab strip; horizontal rows (classes, label first, label names the
control), kept on every tab; CONTROL: no `layout` and `vertical` draw no
grid row; the two tab-rule helpers.
## Acceptance notes
- The horizontal arrangement keys on the viewport `sm` breakpoint, as
the dispatch reading asked, not on a container query: a form with no
container ancestor would never engage a container variant. Inside a
narrow dialog at a wide viewport the label column is still 10rem.
- `SplitForm` and `WizardForm` (plugin-form) also hard-code `layout:
'vertical'` on the form node they build, so a split or wizard form view
drops `horizontal` the same way `TabbedForm` did. Outside this card's
file surface; reported to the seat.
- On the form page, `type` values `wizard`, `split`, `drawer` and
`modal` still draw stacked sections (unchanged; outside this card,
reported to the seat).
- A tabbed form-page section with neither `name` nor heading labels its
tab with its position number (the app's `TabbedForm` writes an English
`Tab N`); no catalogue key exists for either.
## Verification
All readings on head `763ea858` (branch tip after merging `origin/main`)
unless noted.
<details><summary>New tests and wider suites</summary>
- New files: 3 files, 21 tests, all pass (5 + 3 + 13).
- `pnpm --dir ui exec vitest run --maxWorkers=2
packages/components/src/renderers/form/ packages/plugin-form/
apps/console/src/components/` under the verify lock: Test Files 333
passed (333), Tests 3538 passed, 18 skipped; VERDICT command-exit 0.
- Type check: `pnpm --filter @object-ui/components run type-check`,
`@object-ui/plugin-form`, `@object-ui/console` each exit 0 (console
after its closure build `--filter '@object-ui/console^...'`, VERDICT
command-exit 0).
- ESLint on the six changed source and test files: 0 errors (warnings
are pre-existing `any` / exhaustive-deps lines).
- `pnpm --dir ui run check:new-line-citations`: 0 new citations.
</details>
<details><summary>Ablations (each restored, blob equal to HEAD, git diff
HEAD empty)</summary>
Run with `node scripts/ablation-replace.mjs` on the pre-merge head
`51be1b76`; each anchor hit once and the mutation was verified on disk.
The three test files import their subject by relative path, so no dist
leg.
- form renderer: `? cn(colSpanClass, HORIZONTAL_FIELD_ITEM_CLASS)`
replaced by `? colSpanClass || undefined` turns 3 tests red (grid
classes, sm-prefix, label-less field).
- TabbedForm: `layout: schema.layout ?? 'vertical',` replaced by
`layout: 'vertical',` turns 1 test red (every field on every tab
horizontal).
- FormPage tabs: `tabbedView` forced false turns 5 tests red (strip,
defaultTab, tab click, tabPosition, refused submit opens the tab). The
submit-carries-every-field test stays green on stacked sections, as a
guard should.
- FormPage rows: `horizontalRows` forced false turns 2 tests red.
</details>
<details><summary>Geometry in Chromium</summary>
The item and row classes compiled with the repository's Tailwind 4
(`compile` from `tailwindcss`, which emitted the `not(label)` child
rule) and drawn in the preinstalled Chromium. At 1024px: label x 16
width 160, input x 192, label vertically inside the input's box,
description under the input at x 192. At 375px: label above the input,
both at x 16. One-off measurement, not committed.
</details>
<details><summary>Gates</summary>
`node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derives 34 families on this change set (same
list before and after the merge). Each ran on `763ea858` with its exit
code captured before any pipe: 34 of 34 exit 0. `dispatch-gates --ran`:
34 derived, 34 run, 0 NOT-MEASURED. `node
scripts/check-sdui-manifest.mjs` is among them (exit 0). On the
pre-merge head the `ui/scripts` vitest family first exited 1 on two
tree-walking tests that timed out at 15 s while a 20-minute locked suite
shared the box; rerun under the lock it passed (175 files), and it
passed again on `763ea858`.
</details>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01JQwxbXNVYZR3yMKLPJJvzL
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 48bffe3 commit 2d05cd4
9 files changed
Lines changed: 779 additions & 93 deletions
File tree
- .changeset
- ui
- apps/console/src/components
- content/docs/components/form
- packages
- components/src/renderers/form
- __tests__
- plugin-form
- src
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
0 commit comments