Skip to content

Commit 0a3ea67

Browse files
fix(ui): long-text fields read label-on-top on the record page, headings one step smaller (#37901)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} --> _Requested by **Tesla** · [project thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoAoNwrZVJoUEFfvMURpRPKJ)_ Fixes #37801 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:记录页字段区里,多行文本、Markdown、富文本、多文件这类长字段改为标签在上、正文占满整列(实测正文从 212px 宽到 336px);字段里的 Markdown/富文本标题缩小一档(一级标题 30px 变 18px)。 - 为什么做:记录页阅读样式三张卡里的第一张(不改元数据、不需新增设计记录的那一半),替制度类长正文在左栏被挤成窄条的问题解决。 - 出错会怎样:只影响记录页字段区长字段的排版与正文标题字号,不改数据和元数据;有问题可直接撤回本 PR。 - 要你做什么:无。 ## What changes - **Field list, wide fields label-on-top** (`DetailSection.tsx`, frameless row only). A field for which the auto layout's own `isWideDetailField` is true (`textarea`, `markdown`, `html`, `richtext`, `grid`, or `file` / `image` with `multiple: true` on the object field) draws its label above the value: the row becomes `flex-col` (stretched), the label drops its `w-28 shrink-0` column. No second type list. The predicate is asked of the enriched field (view entry merged with the object field), so a section entry that carries no `type` still resolves through the object field — the same type the cell renderer draws with. Every other field keeps the label-left row. `data-detail-field`, `data-detail-field-row`, `data-detail-field-label` and the click-to-edit target (the value box, its `title`, the in-place editor anchor) are unchanged. The boxed face and the mobile grouped-inset face are untouched. - **Document face headings one step smaller** (`richTextDisplay.tsx`). `RICH_TEXT_DOCUMENT_CLASS` = the shared typography + `prose-h1:text-lg prose-h2:text-base prose-h3:text-sm`. Elements stay `h1`–`h6` (the `?section=` anchor reads them). `RICH_TEXT_CELL_FACE_CLASS` is now built from the shared base, not from the document class, so it is byte-identical to before (pinned). Markdown and html/richtext read the one constant. The comment cites objectstack#36344. - One patch changeset for `@object-ui/plugin-detail` + `@object-ui/fields`. ## Tests - `ui/packages/plugin-detail/src/__tests__/DetailSection.wideFieldLabelTop-37801.test.tsx` — on the field list: `textarea`, `markdown`, `html`, `richtext` and multi-file rows are label-on-top (column, label first, no fixed width, value `min-w-0 flex-1`), rows keep `data-detail-field` / `data-detail-field-row`; `text`, `select` and single `file` keep the label-left row; a section entry without `type` resolves through the object field; a click on a wide value still calls `onEnterInlineEdit` and the value keeps its `Click to edit` title; the boxed face is unchanged. - `ui/packages/fields/src/__tests__/richTextDocumentHeadings-37801.test.tsx` — document face: markdown h1–h4 are still h1–h4 under the three size modifiers; html and richtext carry the same class string as markdown; the cell-face class is byte-for-byte the old string; in a grid column neither pipeline draws a heading element or a size modifier. - Ablation (committed fix, `scripts/ablation-replace.mjs`, restore proven by blob == HEAD and empty `git diff HEAD`): forcing `labelOnTop` false reds 6 of 9 in the plugin-detail file (the five wide rows and the no-type case); removing the three modifiers reds 2 of 6 in the fields file (markdown sizes, class composition). <details><summary>Readings at head 2258e16</summary> - New pins + `markdownCellHeading-36344`: Test Files 3 passed (3), Tests 24 passed (24). - `pnpm --dir ui exec vitest run packages/plugin-detail/ packages/fields/` plus `app-shell` `recordSectionAnchor.test.tsx` and `RecordDetailView.citedSection-37365.test.tsx`: Test Files 760 passed, 2 skipped (762); Tests 9146 passed, 25 skipped (9171); lock VERDICT command-exit 0. - `type-check` for `@object-ui/plugin-detail` and `@object-ui/fields` (both `tsc --noEmit` and `tsc -p tsconfig.test.json`, whose include is every `src/**/*.test.tsx`): VERDICT command-exit 0. - `dispatch-gates.mjs --commands` derived 38 families for this diff; all 38 ran locally, every one exit 0 (`pnpm --dir ui exec vitest run scripts/`: 172 files passed, 2 skipped; 5138 tests passed). `--ran` reconciliation: 38 derived, 38 run, 0 NOT-MEASURED, 0 UNRUN. - `ui` `check:new-line-citations`: 0 new citation(s). </details> ## Acceptance notes - The value box now spans the full column (412 px including the 6 px hover bleed each side the editable value already had; the boxed face uses the same bleed to sit flush with a label above). The text block inside it measured 336 px, not 400: the field-history and copy buttons beside the value reserve 64 px (two 24 px buttons and their gaps) even while hidden at rest. That reservation is existing behaviour of the value box on every face and is not in this card's surface; moving those buttons onto the label line would give a wide field the remaining 64 px. Noted, not filed (polish). - `ui/packages/fields/src/index.tsx` still says, in the `inGridColumn` prop's comment, that the record page "keeps the heading sizes": it keeps the document face's sizes, which are now one step smaller. Outside this card's file surface; left as is. - `ui/AGENTS.md` #2 (docs-driven) asks for the package README and a `content/docs/frontend/` page on a feature change; this card's surface names neither, so no docs edit is in this PR. - The smaller headings reach every document-face caller of the rich-content pipelines, a readonly form field included, by design of the card (one face, one constant). ## Verification Browser check, showcase app (`examples/app-showcase`, own backend on a private port with `--fresh`, Console dev server from `ui/` source pointed at it), record `Specimen — Full` of `showcase_field_zoo` with a long markdown policy body, viewport 1204×1007, laid-out record page (field list in the left column, `data-detail-section-list` present). Screenshots were taken locally; the relay carries no image upload, so the measured values are given here. | Reading | Before (origin/main 7ad103a) | After (2258e16) | |---|---|---| | Markdown row direction | row | column | | Label box | 112 × 32 px, left | 400 × 28 px, above | | Value box width | 288 px | 412 px | | Text block width (markdown and textarea) | 212 px | 336 px | | Markdown row height | 1281 px | 818 px | | h1 / h2 / h3 / body font size | 30 / 20 / 18 / 14 px | 18 / 16 / 14 / 14 px | | Select row (control) | row, label 112 px | row, label 112 px | | Page `scrollWidth` | 1204 | 1204 | A click on the textarea value opened the in-place editor anchored on the value box: anchor and popover both x 48, width 336 px. Two-minute check: `pnpm --dir ui exec vitest run packages/plugin-detail/src/__tests__/DetailSection.wideFieldLabelTop-37801.test.tsx packages/fields/src/__tests__/richTextDocumentHeadings-37801.test.tsx` — expect 15 tests passed. In the app, open any record with a markdown field on the record page: the label sits above the body, which spans the column, and an `# H1` in it reads at 18 px. Read first (by risk): `ui/packages/plugin-detail/src/DetailSection.tsx` (the `labelOnTop` branch on the row and label classes), `ui/packages/fields/src/widgets/richTextDisplay.tsx` (the cell face now built from the shared base, not from the document class). --- _Generated by [Claude Code](https://claude.ai/code/session_01L9qibx7DSQZnugnuX8CpCM)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent d58bf7a commit 0a3ea67

8 files changed

Lines changed: 370 additions & 11 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@object-ui/plugin-detail': patch
3+
'@object-ui/fields': patch
4+
---
5+
6+
fix(ui): long-text fields on the record page read label-on-top across the whole column, and a rich-text body's headings draw one step smaller
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
On the record page's field list every field drew its label in a 112 px column to the left of its value, so a long body (a `textarea`, `markdown`, `html` or `richtext` field, or a `file` / `image` field declared `multiple: true`) was set in what that column left over. Those fields, the same set the detail layout already spans across a full row, now draw the label above the value and give the value the whole column. Every other field keeps its label-left row, and a click on the value still edits it.
12+
13+
A `markdown`, `html` or `richtext` value drawn in full (the record page, a readonly form field) draws `h1` at 18 px, `h2` at 16 px and `h3` at 14 px instead of 30, 20 and 18 px. The headings are still heading elements, so a link to a cited section still finds them; a value drawn in a grid cell is unchanged. No metadata changes.

‎content/docs/frontend/plugins/plugin-detail.mdx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,17 @@ declare const handleAddComment: (text: string) => void;
195195
- **Positioning**: Panel can be placed at `bottom`, `right`, or `left` of the record view
196196
- **Collapsible**: Optional collapse/expand with configurable default state
197197

198+
## How a field is drawn on the record page
199+
200+
The default record page's field list draws one field a row: the label left,
201+
the value beside it. A wide field (`textarea`, `markdown`, `html`, `richtext`,
202+
`grid`, or `file` / `image` declared `multiple: true`) draws its label above
203+
the value instead, and the value takes the column's whole width; a click on it
204+
still edits it. In a `markdown`, `html` or `richtext` body, `h1`–`h3` read one
205+
step smaller than the typography scale (18 / 16 / 14 px) and stay heading
206+
elements, so a link to a cited section still finds them. A grid cell flattens
207+
headings to a bold line at its own size.
208+
198209
## Editing a field on the record page
199210

200211
A record page offers two ways to edit, and both save through
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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#37801 — in the document face (the record page, a readonly form
11+
* field) a rich-content value draws its top three heading levels one step
12+
* smaller than `prose-sm` does, and keeps them heading ELEMENTS.
13+
*
14+
* `prose-sm` draws an `h1` at 30 px inside one field of a record page. The
15+
* document face now carries `prose-h1:text-lg prose-h2:text-base
16+
* prose-h3:text-sm`. The elements stay `h1`–`h6`, because a `?section=` link
17+
* finds a cited section by its heading element; the cell face, which draws no
18+
* heading element (objectstack#36344, objectstack#36452), is unchanged.
19+
*
20+
* jsdom does no layout, so these pins read the element and class contract the
21+
* sizes rest on; the pixel readings are in the pull request.
22+
*/
23+
24+
import { describe, it, expect, afterEach } from 'vitest';
25+
import React from 'react';
26+
import { render, waitFor, cleanup } from '@testing-library/react';
27+
import '@testing-library/jest-dom';
28+
// Module scope, with the SAME specifier `MarkdownCellRenderer`'s `React.lazy`
29+
// factory uses, so the lazy chunk is resolved before any assertion runs.
30+
import '../widgets/MarkdownContent.js';
31+
import { getCellRenderer, resolveCellRendererType } from '../index';
32+
import { RICH_TEXT_CELL_FACE_CLASS, RICH_TEXT_DOCUMENT_CLASS } from '../widgets/richTextDisplay';
33+
34+
const HEADING_SIZES = ['prose-h1:text-lg', 'prose-h2:text-base', 'prose-h3:text-sm'];
35+
36+
afterEach(() => cleanup());
37+
38+
async function renderFace(type: 'markdown' | 'html' | 'richtext', value: string, props: { inGridColumn?: boolean } = {}) {
39+
const Renderer = getCellRenderer(resolveCellRendererType({ type }) || type);
40+
const utils = render(<Renderer value={value} field={{ type } as any} {...props} />);
41+
const marker = type === 'markdown' ? '[data-markdown-face]' : '[data-html-face]';
42+
const face = await waitFor(() => {
43+
const el = utils.container.querySelector<HTMLElement>(marker);
44+
if (!el) throw new Error(`${type} body not rendered yet`);
45+
return el;
46+
});
47+
return { ...utils, face };
48+
}
49+
50+
const MARKDOWN = ['# One', '## Two', '### Three', '#### Four'].join('\n\n');
51+
const HTML = '<h1>One</h1><h2>Two</h2><h3>Three</h3><h4>Four</h4>';
52+
53+
describe('objectstack#37801 — the document face draws h1–h3 one step smaller, as heading elements', () => {
54+
it('markdown: h1–h4 are still h1–h4, under the smaller heading sizes', async () => {
55+
const { face } = await renderFace('markdown', MARKDOWN);
56+
expect(face).toHaveAttribute('data-markdown-face', 'document');
57+
expect(face.querySelector('h1')).toHaveTextContent('One');
58+
expect(face.querySelector('h2')).toHaveTextContent('Two');
59+
expect(face.querySelector('h3')).toHaveTextContent('Three');
60+
expect(face.querySelector('h4')).toHaveTextContent('Four');
61+
expect(face).toHaveClass('prose', 'prose-sm', ...HEADING_SIZES);
62+
});
63+
64+
for (const type of ['html', 'richtext'] as const) {
65+
it(`${type}: h1–h4 are still h1–h4, under the same heading sizes as markdown`, async () => {
66+
const { face } = await renderFace(type, HTML);
67+
expect(face).toHaveAttribute('data-html-face', 'document');
68+
for (const [tag, text] of [['h1', 'One'], ['h2', 'Two'], ['h3', 'Three'], ['h4', 'Four']]) {
69+
expect(face.querySelector(tag)).toHaveTextContent(text);
70+
}
71+
const md = await renderFace('markdown', MARKDOWN);
72+
expect(face.className).toBe(md.face.className);
73+
});
74+
}
75+
76+
it('the document face is the shared typography plus the heading sizes, and nothing of the cell face', () => {
77+
const tokens = RICH_TEXT_DOCUMENT_CLASS.split(/\s+/);
78+
expect(tokens).toEqual(expect.arrayContaining(HEADING_SIZES));
79+
expect(tokens).not.toContain('text-[length:inherit]');
80+
expect(tokens).not.toContain('leading-[inherit]');
81+
});
82+
83+
it('CONTROL — the cell face class is byte-for-byte what it was, with no heading size', () => {
84+
expect(RICH_TEXT_CELL_FACE_CLASS).toBe(
85+
'prose prose-sm max-w-none dark:prose-invert break-words text-[length:inherit] leading-[inherit]',
86+
);
87+
});
88+
89+
it('CONTROL — in a grid column markdown and html draw no heading element and no heading size', async () => {
90+
const md = await renderFace('markdown', MARKDOWN, { inGridColumn: true });
91+
const html = await renderFace('html', HTML, { inGridColumn: true });
92+
for (const face of [md.face, html.face]) {
93+
expect(face.querySelector('h1, h2, h3, h4, h5, h6')).toBeNull();
94+
expect(face.className).toBe(RICH_TEXT_CELL_FACE_CLASS);
95+
for (const size of HEADING_SIZES) expect(face).not.toHaveClass(size);
96+
}
97+
});
98+
});

‎ui/packages/fields/src/index.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ export interface CellRendererProps {
450450
* (objectstack#36344): a heading is a bold line at the cell's own text size
451451
* instead of a heading element, so a value that starts with `# Heading`
452452
* keeps the row's height. The record page does not pass it and keeps the
453-
* heading sizes.
453+
* heading elements, at the document face's sizes (objectstack#37801).
454454
*
455455
* A `date` field that declares no `format` then paints `formatDate`'s
456456
* absolute default face instead of `'relative'`, and the relative phrase

‎ui/packages/fields/src/widgets/richTextDisplay.tsx‎

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ const LazyMarkdownContent = recoverableLazy(() => import('./MarkdownContent.js')
4646
* pipeline the field type reads through.
4747
*
4848
* - `document` — a full-size display (the record page, a readonly form field):
49-
* headings keep their heading elements and the typography scale's sizes.
49+
* headings keep their heading elements, one step smaller than the
50+
* typography scale draws them (objectstack#37801).
5051
* - `cell` — one cell of a grid column, whose row is one line of the cell's own
5152
* text (objectstack#36344, objectstack#36452). A heading is drawn as a bold
5253
* line at the cell's text size, not as a heading element, and the body
@@ -55,11 +56,33 @@ const LazyMarkdownContent = recoverableLazy(() => import('./MarkdownContent.js')
5556
*/
5657
export type RichTextFace = 'document' | 'cell';
5758

58-
/** The document face: the typography scale at its own sizes. */
59-
export const RICH_TEXT_DOCUMENT_CLASS = 'prose prose-sm max-w-none dark:prose-invert break-words';
59+
/** The typography both faces are drawn with. */
60+
const RICH_TEXT_FACE_BASE_CLASS = 'prose prose-sm max-w-none dark:prose-invert break-words';
6061

61-
/** The cell face: the same typography, at the size and line height of the cell around it. */
62-
export const RICH_TEXT_CELL_FACE_CLASS = `${RICH_TEXT_DOCUMENT_CLASS} text-[length:inherit] leading-[inherit]`;
62+
/**
63+
* The document face: the typography scale, its top three heading levels one
64+
* step smaller (objectstack#37801).
65+
*
66+
* `prose-sm` sets a body of 14 px under an `h1` of 30 px, an `h2` of 20 px and
67+
* an `h3` of 18 px: a document's scale, drawn here inside one field of a
68+
* record page whose own group titles are 14 px. The modifiers set `h1` 18 px,
69+
* `h2` 16 px and `h3` 14 px (still semibold), so a body's outline still reads
70+
* in order and no field's heading outshouts the page around it.
71+
*
72+
* Only the SIZE moves. The elements stay `h1`–`h6`: a `?section=` link finds a
73+
* cited section by its heading element (`recordSectionAnchor.ts`), and the cell
74+
* face below is the one that draws no heading element (objectstack#36344). The
75+
* markdown and the html / richtext pipelines read this one constant, so the
76+
* two draw a heading at the same size.
77+
*/
78+
export const RICH_TEXT_DOCUMENT_CLASS = `${RICH_TEXT_FACE_BASE_CLASS} prose-h1:text-lg prose-h2:text-base prose-h3:text-sm`;
79+
80+
/**
81+
* The cell face: the same typography, at the size and line height of the cell
82+
* around it. Built on the shared base, not on the document face, so the
83+
* document face's heading sizes never reach a grid cell.
84+
*/
85+
export const RICH_TEXT_CELL_FACE_CLASS = `${RICH_TEXT_FACE_BASE_CLASS} text-[length:inherit] leading-[inherit]`;
6386

6487
type HeadingTag = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
6588
type CellHeadingComponent = (props: { children?: React.ReactNode }) => React.ReactElement;
@@ -145,7 +168,7 @@ function richTextSource(value: unknown): string | undefined {
145168
* (objectstack#36344): a heading is a bold line at the cell's own text size,
146169
* so a value that starts with `# Heading` does not grow its row. Every other
147170
* caller — the record page, a readonly form field — keeps the `document`
148-
* face and its heading sizes.
171+
* face and its heading elements, at the face's sizes (objectstack#37801).
149172
*/
150173
export function MarkdownCellRenderer({ value, inGridColumn }: CellRendererProps): React.ReactElement {
151174
const text = richTextSource(value);
@@ -185,7 +208,8 @@ export function MarkdownCellRenderer({ value, inGridColumn }: CellRendererProps)
185208
* not grow its row. The face changes only which elements the SANITIZED tree
186209
* is drawn with; what the sanitiser keeps and drops is the same in both
187210
* faces. Every other caller — the record page, a readonly form field — keeps
188-
* the `document` face and its heading sizes.
211+
* the `document` face and its heading elements, at the face's sizes
212+
* (objectstack#37801).
189213
*
190214
* The parse is memoised on the text and the face for cost only (a grid
191215
* renders many cells); nothing depends on the identity of the memoised value.

‎ui/packages/plugin-detail/README.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,15 @@ ignored. `tier` (`recordPageTierFor`) is still taken and stamped on the page as
908908
`data-record-page-tier`, but the layout above is decided by the page
909909
content's own measured width.
910910
911+
Wherever the details take one field a row, a row is the label left in a 112 px
912+
column and the value beside it. A wide field (`textarea`, `markdown`, `html`,
913+
`richtext`, `grid`, or `file` / `image` declared `multiple: true` — the fields
914+
`isWideDetailField` spans across a full row) draws its label above the value
915+
instead, and the value takes the column's whole width. A click on the value
916+
still edits it. A `markdown`, `html` or `richtext` body draws its `h1`–`h3`
917+
one step smaller than `prose-sm` (18 / 16 / 14 px); they stay heading elements,
918+
so a `?section=` link still finds them.
919+
911920
On a pinned page the left column narrows on its own to leave the tabs 400 px,
912921
never below 320 px; under that the page is no longer pinned and the details
913922
become its first tab again. The divider between the column and the tabs is a

‎ui/packages/plugin-detail/src/DetailSection.tsx‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import {
5555
ReferenceChipContext,
5656
} from '@object-ui/fields';
5757
import type { DetailViewSection as DetailViewSectionType, DetailViewField, FieldMetadata } from '@object-ui/types';
58-
import { applyDetailAutoLayout } from './autoLayout';
58+
import { applyDetailAutoLayout, isWideDetailField } from './autoLayout';
5959
import { useDetailTranslation } from './useDetailTranslation';
6060
import { useSafeFieldLabel } from '@object-ui/react';
6161
import { NON_EDITABLE_SYSTEM_FIELDS } from './systemFields';
@@ -971,11 +971,23 @@ export const DetailSection: React.FC<DetailSectionProps> = ({
971971
// The frameless face (the default record page) draws a dense row: the
972972
// label left in a fixed-width 12 px muted column, the value right at
973973
// 13 px, one 32 px line for a one-line value.
974+
// objectstack#37801 — a WIDE field (long text, markdown, html, rich text,
975+
// a multi-file list: the one `isWideDetailField` predicate the auto layout
976+
// spans by, never a second type list) draws its label ABOVE the value
977+
// instead, and the value takes the column's whole width rather than what a
978+
// 112 px label column leaves of it. The row keeps its attributes and its
979+
// click target; only its direction moves.
980+
const labelOnTop =
981+
frameless && isWideDetailField(enrichedField as DetailViewField, objectSchema?.fields);
974982
return (
975983
<div
976984
key={field.name}
977985
className={cn(
978-
frameless ? 'group flex min-w-0 items-start gap-3' : 'space-y-1.5 group min-w-0',
986+
frameless
987+
? labelOnTop
988+
? 'group flex min-w-0 flex-col'
989+
: 'group flex min-w-0 items-start gap-3'
990+
: 'space-y-1.5 group min-w-0',
979991
frameless ? framelessSpanClass(field.span, framelessColumns) : spanClass,
980992
// The field list (objectstack#36147): one row under the other, a
981993
// hairline between them.
@@ -992,7 +1004,9 @@ export const DetailSection: React.FC<DetailSectionProps> = ({
9921004
<div
9931005
className={
9941006
frameless
995-
? 'w-28 shrink-0 truncate py-1 text-xs leading-6 text-muted-foreground'
1007+
? labelOnTop
1008+
? 'truncate pt-1 text-xs leading-6 text-muted-foreground'
1009+
: 'w-28 shrink-0 truncate py-1 text-xs leading-6 text-muted-foreground'
9961010
: 'text-xs font-medium text-muted-foreground'
9971011
}
9981012
title={frameless ? fieldLabelText : undefined}

0 commit comments

Comments
 (0)