Skip to content

Commit 11ac230

Browse files
authored
fix(richtext-lexical): consistent html converter inline padding (#12848)
Fixes #12847 - Uses rem instead of em for inline padding, for indent consistency between nodes with different font sizes - Use rem instead of px in deprecated html converters for consistency --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1210564720112211
1 parent 4831f66 commit 11ac230

File tree

5 files changed

+10
-9
lines changed

5 files changed

+10
-9
lines changed

packages/richtext-lexical/src/features/blockquote/server/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const BlockquoteFeature = createServerFeature({
5353
})
5454
const style = [
5555
node.format ? `text-align: ${node.format};` : '',
56-
node.indent > 0 ? `padding-inline-start: ${node.indent * 40}px;` : '',
56+
node.indent > 0 ? `padding-inline-start: ${Number(node.indent) * 2}rem;` : '',
5757
]
5858
.filter(Boolean)
5959
.join(' ')

packages/richtext-lexical/src/features/converters/lexicalToHtml/shared/findConverterForNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export function findConverterForNode<
8383

8484
if (!disableIndent && (!Array.isArray(disableIndent) || !disableIndent?.includes(node.type))) {
8585
if ('indent' in node && node.indent && node.type !== 'listitem') {
86-
style['padding-inline-start'] = `${Number(node.indent) * 2}em`
86+
style['padding-inline-start'] = `${Number(node.indent) * 2}rem`
8787
}
8888
}
8989

packages/richtext-lexical/src/features/converters/lexicalToHtml_deprecated/converter/converters/paragraph.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const ParagraphHTMLConverter: HTMLConverter<SerializedParagraphNode> = {
3131
})
3232
const style = [
3333
node.format ? `text-align: ${node.format};` : '',
34-
node.indent > 0 ? `padding-inline-start: ${node.indent * 40}px;` : '',
34+
node.indent > 0 ? `padding-inline-start: ${Number(node.indent) * 2}rem;` : '',
3535
]
3636
.filter(Boolean)
3737
.join(' ')

packages/richtext-lexical/src/features/heading/server/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const HeadingFeature = createServerFeature<
7171
})
7272
const style = [
7373
node.format ? `text-align: ${node.format};` : '',
74-
node.indent > 0 ? `padding-inline-start: ${node.indent * 40}px;` : '',
74+
node.indent > 0 ? `padding-inline-start: ${Number(node.indent) * 2}rem;` : '',
7575
]
7676
.filter(Boolean)
7777
.join(' ')

test/lexical/collections/Lexical/e2e/main/e2e.spec.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,23 +1296,24 @@ describe('lexicalMain', () => {
12961296
await page.getByLabel('Title*').fill('Indent and Text-align')
12971297
await page.getByRole('paragraph').nth(1).click()
12981298
await context.grantPermissions(['clipboard-read', 'clipboard-write'])
1299-
const htmlContent = `<p style='text-align: center;'>paragraph centered</p><h1 style='text-align: right;'>Heading right</h1><p>paragraph without indent</p><p style='padding-inline-start: 40px;'>paragraph indent 1</p><h2 style='padding-inline-start: 80px;'>heading indent 2</h2><blockquote style='padding-inline-start: 120px;'>quote indent 3</blockquote>`
1299+
const getHTMLContent: (indentToSize: (indent: number) => string) => string = (indentToSize) =>
1300+
`<p style='text-align: center;'>paragraph centered</p><h1 style='text-align: right;'>Heading right</h1><p>paragraph without indent</p><p style='padding-inline-start: ${indentToSize(1)};'>paragraph indent 1</p><h2 style='padding-inline-start: ${indentToSize(2)};'>heading indent 2</h2><blockquote style='padding-inline-start: ${indentToSize(3)};'>quote indent 3</blockquote>`
13001301
await page.evaluate(
13011302
async ([htmlContent]) => {
1302-
const blob = new Blob([htmlContent], { type: 'text/html' })
1303+
const blob = new Blob([htmlContent as string], { type: 'text/html' })
13031304
const clipboardItem = new ClipboardItem({ 'text/html': blob })
13041305
await navigator.clipboard.write([clipboardItem])
13051306
},
1306-
[htmlContent],
1307+
[getHTMLContent((indent: number) => `${indent * 40}px`)],
13071308
)
13081309
// eslint-disable-next-line playwright/no-conditional-in-test
13091310
const pasteKey = process.platform === 'darwin' ? 'Meta' : 'Control'
13101311
await page.keyboard.press(`${pasteKey}+v`)
13111312
await page.locator('#field-richText').click()
13121313
await page.locator('#field-richText').fill('asd')
1313-
await page.getByRole('button', { name: 'Save' }).click()
1314+
await saveDocAndAssert(page)
13141315
await page.getByRole('link', { name: 'API' }).click()
1315-
const htmlOutput = page.getByText(htmlContent)
1316+
const htmlOutput = page.getByText(getHTMLContent((indent: number) => `${indent * 2}rem`))
13161317
await expect(htmlOutput).toBeVisible()
13171318
})
13181319

0 commit comments

Comments
 (0)