Skip to content

Commit 06c3e5a

Browse files
fix(fields): an html or richtext cell holding a heading keeps the list row one line high (#36566)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9GPJ8pmbK219Pay95x25Uno)_ Fixes #36452 Clause-②: no Metadata-protocol: none ## 维护者速读 - 列表里富文本或 HTML 字段的值以标题开头时,这一行原来会被撑高,现在和其他行一样高、标题按单元格字号加粗显示;记录详情页和只读表单里的标题仍是原来的大字号。 - 这是上一张卡(列表里 Markdown 标题按单元格字号显示)的同类补齐,替所有在列表里看富文本字段的用户解决行高不齐。 - 出错的话,最坏是列表单元格里的标题显示成普通加粗文字或仍偏大,不影响数据和内容过滤安全,可直接撤回此改动。 - 无 ## What changes - `HtmlCellRenderer` (the `html` and `richtext` display pipeline) now reads `inGridColumn`. In a grid column it draws the sanitized tree in the same `cell` face the markdown cell got: every heading level is a `p.font-semibold` at the cell's own text size, and the body takes the cell's font size and line height. Outside a grid column (record page, readonly form field) nothing changes: heading elements and `prose-sm` sizes stay. - One definition for both pipelines: the face classes and the heading element map move from `MarkdownContent.tsx` into `richTextDisplay.tsx` (`RICH_TEXT_DOCUMENT_CLASS`, `RICH_TEXT_CELL_FACE_CLASS`, `cellFaceHeadings(marker)`), and `MarkdownContent` imports them. They live in `richTextDisplay` rather than in `MarkdownContent` so the html cell does not pull the lazy react-markdown chunk into the eager bundle. None of these is exported from the package barrel. - `renderSanitizedHtml(html, components?)` takes an optional element map handed to `toJsxRuntime`. It is applied after `rehype-sanitize` has run, so it changes how a kept element is drawn, never what is kept: the allow-list and the strip list are untouched. - The html container now carries `data-html-face="cell|document"` (the markdown one already carried `data-markdown-face`); its `innerHTML` is unchanged in the document face, which the 8580 byte-for-byte pin confirms. ## Tests - `ui/packages/fields/src/__tests__/markdownCellHeading-36344.test.tsx` (the cell-heading face harness, new top-level describe): html and richtext in a grid column draw no heading element, the heading is `P.font-semibold` with `data-html-heading`, the face carries `text-[length:inherit] leading-[inherit]`, the script in the value is still stripped; all six levels map; the html and markdown cells produce the same heading tag and class and the same face class; CONTROL for html and richtext outside a grid column keeps the `h1` and the document classes. - `ui/packages/plugin-grid/src/__tests__/ObjectGrid.richTextOneLine-12480.test.tsx` (the grid's rich-text one-line harness, new top-level describe): through `ObjectGrid`, html and richtext cells whose value starts with a heading draw the cell face and `tbody` holds no `h1`..`h6`. - Existing test changed because of this fix: in the same 12480 file, the case "10 rows with a markdown, an html and a richtext column" asserted the html cell inside the clamp holds an `h2`; it now asserts the heading is drawn as `[data-html-heading]` reading `Title`. This is the behaviour the card asks to change. No other existing test was edited. ## Acceptance notes - File surface: the dispatch named `fields/src/**/__tests__/` for tests. The 12480 file under `plugin-grid` was outside it and had to change, because one of its assertions pinned the old heading element in a grid cell. The grid-level pin for this card went into that same file as a top-level describe, per the shared-harness rule. - Not changed, noted: the doc comment on `CellRendererProps.inGridColumn` in `ui/packages/fields/src/index.tsx` still says the prop is read by the `date` and `markdown` cells; the `html` / `richtext` cell now reads it too. That file is outside this card's file surface, so the comment is left for the seat to route. - jsdom has no layout. The pins check the elements and classes that the row height depends on. The pixel readings are below. ## Verification Read these first, by risk: 1. `ui/packages/fields/src/widgets/sanitizedHtml.tsx`: the `components` option on `toJsxRuntime`. This is the sanitizer module, so check that the map is applied after sanitisation and the schema is untouched. 2. `ui/packages/fields/src/widgets/richTextDisplay.tsx`: `HtmlCellRenderer` and `cellFaceHeadings`. 3. `ui/packages/fields/src/widgets/MarkdownContent.tsx`: now imports the shared face. Two-minute check: open any object list whose `html` or `richtext` field holds a value starting with a heading. The row should be as tall as its neighbours, with the heading in bold at the cell's text size. Open the record: the heading should be full size. <details><summary>Measurement (card item 1): through ObjectGrid, before and after</summary> Method: four rows rendered through `ObjectGrid` in jsdom: html holding an h1 heading plus a paragraph, richtext holding the same, markdown starting with a heading, and a plain row. The resulting table markup was then laid out in Chromium (`/opt/pw-browsers/chromium`, 1200 px wide) with the console stylesheet compiled from `ui/apps/console/src/index.css` (Tailwind 4 plus typography). Before (origin/main 87c7bba): `tbody` holds an `H1` in the html row and in the richtext row. Row heights: html 45 px, richtext 45 px, markdown 36 px, plain 36 px. The heading is drawn at font-size 30px, line-height 36px. After (4f80ba1): `tbody` holds no heading element. Row heights: 36 / 36 / 36 / 36 px. The heading is a `P` at font-size 14px, line-height 17.5px, the same as the markdown cell's heading. </details> <details><summary>Ablation (one, on the tested behaviour)</summary> Mutation via `scripts/ablation-replace.mjs`: in `HtmlCellRenderer`, the line that picks `cell` when `inGridColumn` is set was changed to always pick `document` (anchor 1 → 0, blob baccb82 → 9b850e05). Run: the 36344 and 12480 files. Result: 6 failed, 8 passed. The failures were the four html/richtext grid-column cases in the fields harness, the updated 12480 assertion, and the new grid pin. The controls stayed green: the markdown cases and the html/richtext document-face cases. After restore the blob equals HEAD (baccb82) and `git diff HEAD` is empty. </details> <details><summary>Local runs (head 1b5c106, after merging origin/main)</summary> - Dependency closure `turbo run build --filter=@object-ui/plugin-grid^...`: 53/53 tasks, lock VERDICT command-exit 0. - `pnpm --filter @object-ui/fields type-check` and `pnpm --filter @object-ui/plugin-grid type-check`: exit 0 (both test tsconfigs list the changed test files). - `vitest run packages/fields/` plus the 12480 file: Test Files 323 passed, 1 skipped; Tests 4896 passed, 7 skipped; VERDICT command-exit 0. - Before the merge, at 4f80ba1: `vitest run packages/fields/ packages/plugin-grid/`: Test Files 629 passed, 1 skipped; Tests 7604 passed, 7 skipped; VERDICT command-exit 0. - `dispatch-gates.mjs --commands` at 1b5c106: 38 families, each run, all exit 0. `--ran` reconciliation: 38 derived, 38 run, 0 NOT-MEASURED. - `ui` `check:spec-symbols` exit 0; `check:new-line-citations`: 0 new citations. - `test:repo`: owned by CI, not run locally. </details> Session: https://claude.ai/code/session_01ADHkmRGDrq6JSytBsNFabU 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent abe95a9 commit 06c3e5a

6 files changed

Lines changed: 211 additions & 43 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@object-ui/fields': patch
3+
---
4+
5+
fix(fields): an html or richtext cell holding a heading keeps the list row one line high
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
An `html` or `richtext` value that holds a heading drew it as a heading element in a grid cell, at the typography scale's heading size, so the row grew taller than the other rows (45 px against 36 px in Chromium for a stored `<h1>`). In a grid column the cell now draws the value in the same cell face a `markdown` cell uses: every heading level is a bold line at the cell's own text size, and the body takes the cell's font size and line height. What the sanitiser keeps and drops is unchanged. The record page and readonly form fields keep their full-size headings.

‎ui/packages/fields/src/__tests__/markdownCellHeading-36344.test.tsx‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,77 @@ describe('objectstack#36344 — a markdown heading in a grid cell is drawn at th
8686
expect(face).not.toHaveClass('leading-[inherit]');
8787
});
8888
});
89+
90+
/**
91+
* objectstack#36452 — the same face for the `html` and `richtext` cell. Both
92+
* types read through `HtmlCellRenderer`, which drew a stored `<h1>` as a
93+
* heading element in every caller, so a list row holding one grew to the
94+
* heading's line height (45 px against 36 px in Chromium; readings in the
95+
* pull request). In a grid column it now draws the sanitized tree with the
96+
* markdown cell's face; outside one the heading element stays.
97+
*/
98+
const HTML_HEADING_VALUE = '<h1>Heading</h1><p>Body with <strong>bold</strong> text</p><script>alert(1)</script>';
99+
100+
async function renderHtml(type: 'html' | 'richtext', value: string, props: { inGridColumn?: boolean } = {}) {
101+
const Renderer = getCellRenderer(resolveCellRendererType({ type }) || type);
102+
const utils = render(<Renderer value={value} field={{ type } as any} {...props} />);
103+
const face = await waitFor(() => {
104+
const el = utils.container.querySelector<HTMLElement>('[data-html-face]');
105+
if (!el) throw new Error('html body not rendered yet');
106+
return el;
107+
});
108+
return { ...utils, face };
109+
}
110+
111+
describe('objectstack#36452 — an html or richtext heading in a grid cell is drawn at the cell size', () => {
112+
for (const type of ['html', 'richtext'] as const) {
113+
it(`${type} in a grid column: no heading element, the heading is a bold line, the body inherits the cell size`, async () => {
114+
const { face } = await renderHtml(type, HTML_HEADING_VALUE, { inGridColumn: true });
115+
116+
expect(face).toHaveAttribute('data-html-face', 'cell');
117+
expect(face.querySelector(HEADINGS)).toBeNull();
118+
119+
const heading = face.querySelector<HTMLElement>('[data-html-heading]');
120+
expect(heading?.tagName).toBe('P');
121+
expect(heading).toHaveTextContent('Heading');
122+
expect(heading).toHaveClass('font-semibold');
123+
expect(face).toHaveClass('prose', 'prose-sm', 'text-[length:inherit]', 'leading-[inherit]');
124+
125+
// Sanitisation is the same in this face: the script is gone, the rest formatted.
126+
expect(face.querySelector('script')).toBeNull();
127+
expect(face.textContent).not.toContain('alert');
128+
expect(face.querySelector('strong')).toHaveTextContent('bold');
129+
});
130+
}
131+
132+
it('html in a grid column: every heading level is drawn the same way', async () => {
133+
const value = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'].map((tag) => `<${tag}>${tag}</${tag}>`).join('');
134+
const { face } = await renderHtml('html', value, { inGridColumn: true });
135+
expect(face.querySelector(HEADINGS)).toBeNull();
136+
expect(face.querySelectorAll('[data-html-heading]')).toHaveLength(6);
137+
});
138+
139+
it('the markdown and html cells draw a heading with the same element and classes', async () => {
140+
const md = await renderMarkdown('# Heading', { inGridColumn: true });
141+
const mdHeading = md.face.querySelector<HTMLElement>('[data-markdown-heading]');
142+
const html = await renderHtml('html', '<h1>Heading</h1>', { inGridColumn: true });
143+
const htmlHeading = html.face.querySelector<HTMLElement>('[data-html-heading]');
144+
expect(htmlHeading?.tagName).toBe(mdHeading?.tagName);
145+
expect(htmlHeading?.className).toBe(mdHeading?.className);
146+
expect(html.face.className).toBe(md.face.className);
147+
});
148+
149+
for (const type of ['html', 'richtext'] as const) {
150+
it(`CONTROL — ${type} outside a grid column (the record page, a readonly form) keeps the heading element`, async () => {
151+
const { face } = await renderHtml(type, HTML_HEADING_VALUE);
152+
153+
expect(face).toHaveAttribute('data-html-face', 'document');
154+
expect(face.querySelector('h1')).toHaveTextContent('Heading');
155+
expect(face.querySelector('[data-html-heading]')).toBeNull();
156+
expect(face).toHaveClass('prose', 'prose-sm');
157+
expect(face).not.toHaveClass('text-[length:inherit]');
158+
expect(face).not.toHaveClass('leading-[inherit]');
159+
expect(face.querySelector('script')).toBeNull();
160+
});
161+
}
162+
});

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

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,22 @@ import ReactMarkdown, { type Components } from 'react-markdown';
33
import remarkGfm from 'remark-gfm';
44
import rehypeSanitize from 'rehype-sanitize';
55
import { RICH_TEXT_SANITIZE_SCHEMA } from './sanitizedHtml.js';
6+
import {
7+
RICH_TEXT_CELL_FACE_CLASS,
8+
RICH_TEXT_DOCUMENT_CLASS,
9+
cellFaceHeadings,
10+
type RichTextFace,
11+
} from './richTextDisplay.js';
612

713
/**
8-
* The two faces a markdown value is drawn in.
9-
*
10-
* - `document` — a full-size display (the record page, a readonly form field):
11-
* headings keep their heading elements and the typography scale's sizes.
12-
* - `cell` — one cell of a grid column, whose row is one line of the cell's own
13-
* text (objectstack#36344). A heading is drawn as a bold line at the cell's
14-
* text size, not as a heading element, and the body inherits the cell's font
15-
* size and line height, so a value that starts with `# Heading` keeps the row
16-
* the height of every other row.
14+
* The two faces a markdown value is drawn in — the rich-content faces of
15+
* `./richTextDisplay.tsx`, shared with the `html` / `richtext` pipeline
16+
* (objectstack#36344, objectstack#36452).
1717
*/
18-
export type MarkdownFace = 'document' | 'cell';
18+
export type MarkdownFace = RichTextFace;
1919

20-
const DOCUMENT_CLASS = 'prose prose-sm max-w-none dark:prose-invert break-words';
21-
22-
/** The cell face: the same typography, at the size and line height of the cell around it. */
23-
export const MARKDOWN_CELL_FACE_CLASS = `${DOCUMENT_CLASS} text-[length:inherit] leading-[inherit]`;
24-
25-
function CellHeading({ children }: { children?: React.ReactNode }) {
26-
return <p className="font-semibold" data-markdown-heading="">{children}</p>;
27-
}
28-
29-
/**
30-
* In the cell face no heading element is drawn: a heading inside a table cell
31-
* is drawn at heading size by the typography scale, and it would also add one
32-
* entry per row to the page's heading outline.
33-
*/
34-
const CELL_COMPONENTS: Components = {
35-
h1: CellHeading,
36-
h2: CellHeading,
37-
h3: CellHeading,
38-
h4: CellHeading,
39-
h5: CellHeading,
40-
h6: CellHeading,
41-
};
20+
/** In the cell face no heading element is drawn (see `cellFaceHeadings`). */
21+
const CELL_COMPONENTS: Components = cellFaceHeadings('data-markdown-heading');
4222

4323
/**
4424
* Heavy markdown renderer, split into its own module so it can be lazy-loaded
@@ -49,7 +29,7 @@ const CELL_COMPONENTS: Components = {
4929
export default function MarkdownContent({ value, face = 'document' }: { value: string; face?: MarkdownFace }) {
5030
const cell = face === 'cell';
5131
return (
52-
<div className={cell ? MARKDOWN_CELL_FACE_CLASS : DOCUMENT_CLASS} data-markdown-face={face}>
32+
<div className={cell ? RICH_TEXT_CELL_FACE_CLASS : RICH_TEXT_DOCUMENT_CLASS} data-markdown-face={face}>
5333
<ReactMarkdown
5434
remarkPlugins={[remarkGfm]}
5535
rehypePlugins={[[rehypeSanitize, RICH_TEXT_SANITIZE_SCHEMA]]}

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

Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,55 @@ import type { CellRendererProps } from '../index.js';
3939

4040
const LazyMarkdownContent = React.lazy(() => import('./MarkdownContent.js'));
4141

42+
/**
43+
* The two faces a rich-content value is drawn in, shared by the markdown and
44+
* the HTML pipeline so a heading in a grid cell is drawn one way whichever
45+
* pipeline the field type reads through.
46+
*
47+
* - `document` — a full-size display (the record page, a readonly form field):
48+
* headings keep their heading elements and the typography scale's sizes.
49+
* - `cell` — one cell of a grid column, whose row is one line of the cell's own
50+
* text (objectstack#36344, objectstack#36452). A heading is drawn as a bold
51+
* line at the cell's text size, not as a heading element, and the body
52+
* inherits the cell's font size and line height, so a value that starts with
53+
* a heading keeps the row the height of every other row.
54+
*/
55+
export type RichTextFace = 'document' | 'cell';
56+
57+
/** The document face: the typography scale at its own sizes. */
58+
export const RICH_TEXT_DOCUMENT_CLASS = 'prose prose-sm max-w-none dark:prose-invert break-words';
59+
60+
/** The cell face: the same typography, at the size and line height of the cell around it. */
61+
export const RICH_TEXT_CELL_FACE_CLASS = `${RICH_TEXT_DOCUMENT_CLASS} text-[length:inherit] leading-[inherit]`;
62+
63+
type HeadingTag = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
64+
type CellHeadingComponent = (props: { children?: React.ReactNode }) => React.ReactElement;
65+
66+
/**
67+
* The element map the cell face draws headings with: every heading level is a
68+
* `p.font-semibold` carrying `marker`, so the pipeline's own pins can find it.
69+
* A heading element inside a table cell is drawn at heading size by the
70+
* typography scale, and it would also add one entry per row to the page's
71+
* heading outline, so the cell face draws none.
72+
*
73+
* Call it once per pipeline at module scope: the returned components are the
74+
* element types React reconciles against, so a fresh map per render would
75+
* remount every heading.
76+
*/
77+
export function cellFaceHeadings(
78+
marker: 'data-markdown-heading' | 'data-html-heading',
79+
): Record<HeadingTag, CellHeadingComponent> {
80+
const CellHeading: CellHeadingComponent = ({ children }) => (
81+
<p className="font-semibold" {...{ [marker]: '' }}>
82+
{children}
83+
</p>
84+
);
85+
return { h1: CellHeading, h2: CellHeading, h3: CellHeading, h4: CellHeading, h5: CellHeading, h6: CellHeading };
86+
}
87+
88+
/** The HTML pipeline's cell-face headings. */
89+
const HTML_CELL_HEADINGS = cellFaceHeadings('data-html-heading');
90+
4291
/**
4392
* The text a rich-content cell formats, or `undefined` when the record holds
4493
* nothing to format (objectui#8580).
@@ -129,17 +178,36 @@ export function MarkdownCellRenderer({ value, inGridColumn }: CellRendererProps)
129178
* are the stored bytes — its output pinned byte-for-byte in
130179
* `__tests__/cellRenderers.childlessContainer-8580.test.tsx`.
131180
*
132-
* The parse is memoised on the text for cost only (a grid renders many
133-
* cells); nothing depends on the identity of the memoised value.
181+
* In a grid column (`inGridColumn`) the value is drawn in the `cell` face
182+
* (objectstack#36452), the same face the markdown cell draws: every heading
183+
* level is a bold line at the cell's own text size, so a stored `<h1>` does
184+
* not grow its row. The face changes only which elements the SANITIZED tree
185+
* is drawn with; what the sanitiser keeps and drops is the same in both
186+
* faces. Every other caller — the record page, a readonly form field — keeps
187+
* the `document` face and its heading sizes.
188+
*
189+
* The parse is memoised on the text and the face for cost only (a grid
190+
* renders many cells); nothing depends on the identity of the memoised value.
134191
*/
135-
export function HtmlCellRenderer({ value }: CellRendererProps): React.ReactElement {
192+
export function HtmlCellRenderer({ value, inGridColumn }: CellRendererProps): React.ReactElement {
136193
const text = richTextSource(value);
194+
const face: RichTextFace = inGridColumn ? 'cell' : 'document';
137195
const content = React.useMemo(
138-
() => (text === undefined ? undefined : renderSanitizedHtml(text)),
139-
[text],
196+
() =>
197+
text === undefined
198+
? undefined
199+
: renderSanitizedHtml(text, face === 'cell' ? HTML_CELL_HEADINGS : undefined),
200+
[text, face],
140201
);
141202
if (text === undefined) return <EmptyValue />;
142-
return <div className="prose prose-sm max-w-none dark:prose-invert break-words">{content}</div>;
203+
return (
204+
<div
205+
className={face === 'cell' ? RICH_TEXT_CELL_FACE_CLASS : RICH_TEXT_DOCUMENT_CLASS}
206+
data-html-face={face}
207+
>
208+
{content}
209+
</div>
210+
);
143211
}
144212

145213
/**

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import React from 'react';
4747
import { Fragment, jsx, jsxs } from 'react/jsx-runtime';
4848
import rehypeSanitize, { defaultSchema, type Options as Schema } from 'rehype-sanitize';
4949
import { h } from 'hastscript';
50-
import { toJsxRuntime } from 'hast-util-to-jsx-runtime';
50+
import { toJsxRuntime, type Components } from 'hast-util-to-jsx-runtime';
5151

5252
type HastRoot = Parameters<ReturnType<typeof rehypeSanitize>>[0];
5353
type HastChild = HastRoot['children'][number];
@@ -149,13 +149,18 @@ function childrenOf(parent: ParentNode): HastChild[] {
149149
* as a plain string: React renders it as text, so the markup shows as source
150150
* but nothing in it is interpreted. A browser render always takes the
151151
* sanitizing path.
152+
*
153+
* `components` maps element names to the components the SANITIZED tree is
154+
* drawn with — the grid cell face draws headings as bold lines with it. It is
155+
* applied after the sanitiser has run, so it changes how a kept element is
156+
* drawn and never what is kept.
152157
*/
153-
export function renderSanitizedHtml(html: string): React.ReactNode {
158+
export function renderSanitizedHtml(html: string, components?: Partial<Components>): React.ReactNode {
154159
if (typeof DOMParser === 'undefined') return html;
155160
const parsed = new DOMParser().parseFromString(html, 'text/html');
156161
const tree = sanitizeTree({ type: 'root', children: childrenOf(parsed.body) });
157162
// `tableCellAlignToStyle: false` keeps a cell's `align` as the attribute
158163
// it was stored as, rather than rewriting it into a `style` the schema
159164
// would otherwise never let through.
160-
return toJsxRuntime(tree, { Fragment, jsx, jsxs, tableCellAlignToStyle: false });
165+
return toJsxRuntime(tree, { Fragment, jsx, jsxs, components, tableCellAlignToStyle: false });
161166
}

‎ui/packages/plugin-grid/src/__tests__/ObjectGrid.richTextOneLine-12480.test.tsx‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ describe('objectui#12480 — a rich-content cell keeps the one-line row', () =>
129129
const rowClamps = Array.from(row9.querySelectorAll<HTMLElement>('[data-testid="grid-rich-text-one-line"]'));
130130
expect(rowClamps).toHaveLength(3);
131131
await waitFor(() => expect(rowClamps[0].querySelector('ul')).not.toBeNull());
132-
expect(rowClamps[1].querySelector('h2')).not.toBeNull();
132+
// The html cell draws its heading in the cell face (objectstack#36452).
133+
expect(rowClamps[1].querySelector('[data-html-heading]')).toHaveTextContent('Title');
133134
expect(rowClamps[2].querySelector('strong')).not.toBeNull();
134135

135136
// Over-correction control: the plain text column is not clamped this way.
@@ -190,3 +191,33 @@ describe('objectstack#36344 — a markdown heading in a grid cell does not draw
190191
expect(document.querySelector('tbody h1, tbody h2, tbody h3, tbody h4, tbody h5, tbody h6')).toBeNull();
191192
});
192193
});
194+
195+
/**
196+
* objectstack#36452 — the same face for an `html` and a `richtext` cell. Both
197+
* read through the html renderer, which drew a stored `<h1>` as a heading
198+
* element, so the row grew to the heading's line height. jsdom does no layout;
199+
* the pixel readings are in the PR.
200+
*/
201+
describe('objectstack#36452 — an html or richtext heading in a grid cell does not draw at heading size', () => {
202+
it('html and richtext cells whose value starts with a heading draw no heading element in the body', async () => {
203+
desktop();
204+
const rows = [
205+
{ id: 'r1', name: 'Account 1', notes_html: '<h1>Heading</h1><p>Body</p>' },
206+
{ id: 'r2', name: 'Account 2', notes_rich: '<h1>Heading</h1><p>Body</p>' },
207+
{ id: 'r3', name: 'Account 3' },
208+
];
209+
renderGrid(rows, [
210+
{ field: 'name', label: 'Name' },
211+
{ field: 'notes_html', label: 'Html' },
212+
{ field: 'notes_rich', label: 'Rich' },
213+
]);
214+
await waitFor(() => expect(screen.getByText('Account 3')).toBeInTheDocument());
215+
for (const row of bodyRows().slice(0, 2) as HTMLElement[]) {
216+
const face = row.querySelector<HTMLElement>('[data-testid="grid-rich-text-one-line"] [data-html-face]');
217+
expect(face).toHaveAttribute('data-html-face', 'cell');
218+
expect(face).toHaveClass('text-[length:inherit]', 'leading-[inherit]');
219+
expect(face?.querySelector('[data-html-heading]')).toHaveTextContent('Heading');
220+
}
221+
expect(document.querySelector('tbody h1, tbody h2, tbody h3, tbody h4, tbody h5, tbody h6')).toBeNull();
222+
});
223+
});

0 commit comments

Comments
 (0)