fix(richtext-lexical): inaccurate detection of whether the editor is empty or not
This commit is contained in:
@@ -20,15 +20,24 @@ export const richTextValidateHOC = ({
|
||||
} = options
|
||||
|
||||
if (required) {
|
||||
const hasChildren = value?.root?.children?.length
|
||||
const hasChildren = !!value?.root?.children?.length
|
||||
|
||||
const hasOnlyEmptyParagraph =
|
||||
(value?.root?.children?.length === 1 &&
|
||||
value?.root?.children[0]?.type === 'paragraph' &&
|
||||
(value?.root?.children[0] as SerializedParagraphNode)?.children?.length === 0) ||
|
||||
((value?.root?.children[0] as SerializedParagraphNode)?.children?.length === 1 &&
|
||||
(value?.root?.children[0] as SerializedParagraphNode)?.children[0]?.type === 'text' &&
|
||||
(value?.root?.children[0] as SerializedParagraphNode)?.children[0]?.['text'] === '')
|
||||
let hasOnlyEmptyParagraph = false
|
||||
if (value?.root?.children?.length === 1) {
|
||||
if (value?.root?.children[0]?.type === 'paragraph') {
|
||||
const paragraphNode = value?.root?.children[0] as SerializedParagraphNode
|
||||
if (paragraphNode?.children?.length === 0) {
|
||||
hasOnlyEmptyParagraph = true
|
||||
} else if (paragraphNode?.children?.length === 1) {
|
||||
const paragraphNodeChild = paragraphNode?.children[0]
|
||||
if (paragraphNodeChild.type === 'text') {
|
||||
if (!paragraphNodeChild?.['text']?.length) {
|
||||
hasOnlyEmptyParagraph = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasChildren || hasOnlyEmptyParagraph) {
|
||||
return t('validation:required')
|
||||
|
||||
Reference in New Issue
Block a user