fix(editor): is input empty state
- Modified the isEmpty method in both ChatInput and LexicalRichEditor components to check if the editor's content is empty by verifying if the trimmed text content is an empty string. - Added an accessories prop to LexicalRichEditor for improved flexibility in rendering additional UI elements. Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
parent
e8c1d47f84
commit
015f4ea10a
|
|
@ -78,7 +78,7 @@ export const ChatInput = memo(({ onSend, variant, ref: forwardedRef }: ChatInput
|
|||
setCurrentEditor(editor)
|
||||
|
||||
editorState.read(() => {
|
||||
setIsEmpty($getRoot().isEmpty())
|
||||
setIsEmpty($getRoot().getTextContent().trim() === "")
|
||||
})
|
||||
}, [])
|
||||
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ export const LexicalRichEditor = function LexicalRichEditor({
|
|||
enabledPlugins = defaultEnabledPlugins,
|
||||
initalEditorState,
|
||||
plugins,
|
||||
accessories,
|
||||
|
||||
onKeyDown,
|
||||
onChange,
|
||||
|
|
@ -103,12 +104,14 @@ export const LexicalRichEditor = function LexicalRichEditor({
|
|||
root.clear()
|
||||
})
|
||||
},
|
||||
isEmpty: () => editorRef?.getEditorState().read(() => $getRoot().isEmpty()) || false,
|
||||
isEmpty: () =>
|
||||
editorRef?.getEditorState().read(() => $getRoot().getTextContent().trim() === "") || false,
|
||||
}))
|
||||
|
||||
return (
|
||||
<LexicalComposer initialConfig={initialConfig}>
|
||||
<div className={cn("relative cursor-text", className)}>
|
||||
{accessories}
|
||||
<RichTextPlugin
|
||||
contentEditable={
|
||||
<ContentEditable
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ export interface LexicalRichEditorProps {
|
|||
enabledPlugins?: BuiltInPlugins
|
||||
initalEditorState?: InitialEditorStateType
|
||||
plugins?: LexicalPluginFC[]
|
||||
|
||||
accessories?: React.ReactNode[]
|
||||
onLengthChange?: (length: number, editor: LexicalEditor) => void
|
||||
onChange?: (editorState: EditorState, editor: LexicalEditor) => void
|
||||
onKeyDown?: (event: KeyboardEvent) => boolean
|
||||
|
|
|
|||
Loading…
Reference in New Issue