Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(richtext): space list rows like Markdown's lists (#7003)

Cindy Zhang01972bcea5c4
diff --git a/packages/richtext/src/__tests__/MarkdownParitySandbox.a11y.chromium.spec.ts b/packages/richtext/src/__tests__/MarkdownParitySandbox.a11y.chromium.spec.ts
index 829d5811d6..f4ef948efb 100644
--- a/packages/richtext/src/__tests__/MarkdownParitySandbox.a11y.chromium.spec.ts
+++ b/packages/richtext/src/__tests__/MarkdownParitySandbox.a11y.chromium.spec.ts
@@ -471,6 +471,23 @@ test('side by side: shared blocks match core Markdown typography, spacing, and m
block('paragraph-inline')?.querySelector('strong') as Element,
).fontWeight,
inlineCode: styleOf(code?.firstElementChild ?? code),
+ // The distance from one list row to the next, and a row's padding.
+ listRows: (() => {
+ // The list's first two rows, both single lines on each surface.
+ const rows = [
+ ...(block('list-unordered', 'ul')?.querySelectorAll(
+ ':scope > li',
+ ) ?? []),
+ ].slice(0, 2);
+ return rows.length < 2
+ ? null
+ : {
+ pitch:
+ rows[1].getBoundingClientRect().top -
+ rows[0].getBoundingClientRect().top,
+ padding: getComputedStyle(rows[0]).paddingTop,
+ };
+ })(),
// The text inside a header cell, where each surface draws it.
tableHeader: (() => {
const cell = block('table', 'table')?.querySelector('th');
@@ -505,6 +522,7 @@ test('side by side: shared blocks match core Markdown typography, spacing, and m
);
}
expect(richText.strong).toBe(markdown.strong);
+ expect(richText.listRows, 'list rows').toEqual(markdown.listRows);
expect(richText.tableHeader, 'table header text').toEqual(
markdown.tableHeader,
);
diff --git a/packages/richtext/src/editorTheme.ts b/packages/richtext/src/editorTheme.ts
index 8372812e12..57e6242d6b 100644
--- a/packages/richtext/src/editorTheme.ts
+++ b/packages/richtext/src/editorTheme.ts
@@ -39,6 +39,10 @@ const MINOR_HEADING_BEFORE = `calc(${spacingVars['--spacing-4']})`;
const MINOR_HEADING_AFTER = `calc(${spacingVars['--spacing-2']})`;
const TEXT_BLOCK_SPACE = `calc(${spacingVars['--spacing-3']})`;
const WIDE_BLOCK_SPACE = `calc(${spacingVars['--spacing-4']})`;
+const LIST_ITEM_SPACE = `calc(${spacingVars['--spacing-1']})`;
+const LIST_ROW_GAP = `calc(${spacingVars['--spacing-0-5']})`;
+const LIST_ROW_FLUSH = `calc(${spacingVars['--spacing-0']})`;
+const NESTED_LIST_SPACE = `calc(${spacingVars['--spacing-2']})`;
const editorTheme = stylex.create({
paragraph: {
@@ -223,10 +227,33 @@ const editorTheme = stylex.create({
listStyleType: 'none',
paddingInlineStart: spacingVars['--spacing-2'],
},
+ // List items space like core Markdown's compact list rows: 4px padding and
+ // a 2px gap between rows. Lexical puts a nested list in an item of its own
+ // after its parent item; that wrapper adds no top padding and no marker,
+ // and its 8px top margin plus the parent row's padding give the 12px
+ // Markdown leaves between an item's text and its nested list.
listItem: {
- marginBlock: spacingVars['--spacing-0-5'],
+ paddingBlockStart: {
+ default: LIST_ITEM_SPACE,
+ ':has(ul)': spacingVars['--spacing-0'],
+ ':has(ol)': spacingVars['--spacing-0'],
+ },
+ paddingBlockEnd: LIST_ITEM_SPACE,
+ marginBlockStart: {
+ default: LIST_ROW_FLUSH,
+ ':has(ul)': NESTED_LIST_SPACE,
+ ':has(ol)': NESTED_LIST_SPACE,
+ },
+ marginBlockEnd: {
+ default: LIST_ROW_GAP,
+ ':last-child': spacingVars['--spacing-0'],
+ },
// Ensure the marker is shown (some CSS resets set list-style: none on li).
- listStyleType: 'inherit',
+ listStyleType: {
+ default: 'inherit',
+ ':has(ul)': 'none',
+ ':has(ol)': 'none',
+ },
},
link: {
color: colorVars['--color-text-accent'],