Skip to content

Commit 7fc6227

Browse files
authored
fix(richtext-lexical): make div container optional (#10383)
Makes the wrapper container `<div class='payload-richtext'>` optional. This is useful when importing and re-using the `<RichText/>` component as part of another custom component already providing a container.
1 parent 827c75a commit 7fc6227

File tree

1 file changed

+22
-14
lines changed
  • packages/richtext-lexical/src/exports/react/components/RichText

1 file changed

+22
-14
lines changed

packages/richtext-lexical/src/exports/react/components/RichText/index.tsx

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ type RichTextProps = {
3333
* Serialized editor state to render.
3434
*/
3535
data: SerializedEditorState
36+
/**
37+
* If true, removes the container div wrapper.
38+
*/
39+
disableContainer?: boolean
3640
/**
3741
* If true, disables indentation globally. If an array, disables for specific node `type` values.
3842
*/
@@ -47,6 +51,7 @@ export const RichText: React.FC<RichTextProps> = ({
4751
className,
4852
converters,
4953
data: editorState,
54+
disableContainer,
5055
disableIndent,
5156
disableTextAlign,
5257
}) => {
@@ -65,18 +70,21 @@ export const RichText: React.FC<RichTextProps> = ({
6570
finalConverters = defaultJSXConverters
6671
}
6772

68-
return (
69-
<div className={className ?? 'payload-richtext'}>
70-
{editorState &&
71-
!Array.isArray(editorState) &&
72-
typeof editorState === 'object' &&
73-
'root' in editorState &&
74-
convertLexicalToJSX({
75-
converters: finalConverters,
76-
data: editorState,
77-
disableIndent,
78-
disableTextAlign,
79-
})}
80-
</div>
81-
)
73+
const content =
74+
editorState &&
75+
!Array.isArray(editorState) &&
76+
typeof editorState === 'object' &&
77+
'root' in editorState &&
78+
convertLexicalToJSX({
79+
converters: finalConverters,
80+
data: editorState,
81+
disableIndent,
82+
disableTextAlign,
83+
})
84+
85+
if (disableContainer) {
86+
return <>{content}</>
87+
}
88+
89+
return <div className={className ?? 'payload-richtext'}>{content}</div>
8290
}

0 commit comments

Comments
 (0)