Skip to content

Commit 66f5d14

Browse files
authored
fix(richtext-lexical): richtext field duplicates description custom component (#13880)
The lexical field component was accidentally rendering the description component twice. Fixes #13644
1 parent 228e8f2 commit 66f5d14

File tree

5 files changed

+40
-2
lines changed

5 files changed

+40
-2
lines changed

packages/richtext-lexical/src/field/Field.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ const RichTextComponent: React.FC<
184184
/>
185185
{AfterInput}
186186
</ErrorBoundary>
187-
{Description}
188187
<RenderCustomComponent
189188
CustomComponent={Description}
190189
Fallback={<FieldDescription description={description} path={path} />}

packages/ui/src/forms/Form/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export const Form: React.FC<FormProps> = (props) => {
104104
const { startRouteTransition } = useRouteTransition()
105105
const { getUploadHandler } = useUploadHandlers()
106106

107-
const { config, getEntityConfig } = useConfig()
107+
const { config } = useConfig()
108108

109109
const [disabled, setDisabled] = useState(disabledFromProps || false)
110110
const [isMounted, setIsMounted] = useState(false)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const Description = () => {
2+
return (
3+
<div className="lexical-blocks-custom-description" style={{ color: 'red' }}>
4+
My Custom Lexical Description
5+
</div>
6+
)
7+
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,29 @@ describe('lexicalMain', () => {
14461446
page.getByText('Creating new User')
14471447
})
14481448

1449+
test('ensure custom Description component is rendered only once', async () => {
1450+
await navigateToLexicalFields()
1451+
const lexicalWithBlocks = page.locator('.rich-text-lexical').nth(2)
1452+
await lexicalWithBlocks.scrollIntoViewIfNeeded()
1453+
await expect(lexicalWithBlocks).toBeVisible()
1454+
1455+
await expect(lexicalWithBlocks.locator('.lexical-blocks-custom-description')).toHaveCount(1)
1456+
await expect(lexicalWithBlocks.locator('.lexical-blocks-custom-description')).toBeVisible()
1457+
1458+
await expect(lexicalWithBlocks.locator('.field-description')).toHaveCount(0)
1459+
})
1460+
1461+
test('ensure admin.description property is rendered', async () => {
1462+
await navigateToLexicalFields()
1463+
const lexicalSimple = page.locator('.rich-text-lexical').nth(1)
1464+
await lexicalSimple.scrollIntoViewIfNeeded()
1465+
await expect(lexicalSimple).toBeVisible()
1466+
1467+
await expect(lexicalSimple.locator('.field-description')).toHaveCount(1)
1468+
await expect(lexicalSimple.locator('.field-description')).toBeVisible()
1469+
await expect(lexicalSimple.locator('.field-description')).toHaveText('A simple lexical field')
1470+
})
1471+
14491472
test('ensure links can created from clipboard and deleted', async () => {
14501473
await navigateToLexicalFields()
14511474
const richTextField = page.locator('.rich-text-lexical').first()

test/lexical/collections/Lexical/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ export const getLexicalFieldsCollection: (args: {
309309
{
310310
name: 'lexicalSimple',
311311
type: 'richText',
312+
admin: {
313+
description: 'A simple lexical field',
314+
},
312315
editor: lexicalEditor({
313316
features: ({ defaultFeatures }) => [
314317
//TestRecorderFeature(),
@@ -347,6 +350,12 @@ export const getLexicalFieldsCollection: (args: {
347350
{
348351
name: 'lexicalWithBlocks',
349352
type: 'richText',
353+
admin: {
354+
components: {
355+
Description: '/collections/Lexical/components/Description.js#Description',
356+
},
357+
description: 'Should not be rendered',
358+
},
350359
editor: lexicalEditor({
351360
admin: {
352361
hideGutter: false,

0 commit comments

Comments
 (0)