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:
Innei 2025-10-22 21:51:06 +08:00
parent e8c1d47f84
commit 015f4ea10a
No known key found for this signature in database
GPG Key ID: 0F62D33977F021F7
3 changed files with 6 additions and 3 deletions

View File

@ -78,7 +78,7 @@ export const ChatInput = memo(({ onSend, variant, ref: forwardedRef }: ChatInput
setCurrentEditor(editor)
editorState.read(() => {
setIsEmpty($getRoot().isEmpty())
setIsEmpty($getRoot().getTextContent().trim() === "")
})
}, [])

View File

@ -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

View File

@ -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