ClearEditorPlugin is not clearing the ChatComposer text input. #3510
-
BackgroundI upgraded my React and Paste dependencies to be able to import and add the ClearEditorPlugin to the ChatComposer and it initially worked, but after doing a rebase the ClearEditorPlugin doesn't clear the ChatComposer text input. We've tried reinstalling our node_modules and cleaned up our package.json but it still doesn't clear the text box. FeedbackI've tried a few different approaches to get the ClearEditorPlugin working again by reinstalling our node_modules and cleaning up our package.json, so I'm hoping that my issue is dependency related. Currently, it's the missing piece we need in order to complete our ChatComposer implementation. Stage of designNo response ResearchNo response Relevant linksNo response Are you looking for visual design support?
Additional InformationNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @gyasi-eco Thanks for coming to Office Hours, sorry it took a while to follow up here. As we finally came to discover, it wasn't really a versioning problem, just a small implementation detail. As a reminder, Any Lexical Plugin must be registered as a child of the editor, otherwise it doesn't have access to the editor context, which it will need if you want it to do something. <ChatComposer
config={{}}
onChange={handleComposerChange}
>
<ClearEditorPlugin />
<SendButtonPlugin onClick={submitMessage} />
<EnterKeySubmitPlugin onKeyDown={submitMessage} />
</ChatComposer> The As an example the send button plugin. export const SendButtonPlugin = ({ onClick }: { onClick: () => void }): JSX.Element => {
// Grab the editor context that is available as this plugin is a child of the editor
const [editor] = useLexicalComposerContext();
// Do something when the button is clicked
const handleSend = (): void => {
// the callback that was supplied to the plugin to be called when the button is pressed
onClick();
// dispatch the `CLEAR_EDITOR_COMMAND` from the editor, which <ClearEditorPlugin /> is listening for
editor.dispatchCommand(CLEAR_EDITOR_COMMAND, undefined);
};
return (
<Box position="absolute" top="space30" right="space30">
<Button variant="primary_icon" size="reset" onClick={handleSend}>
<SendIcon decorative={false} title="Send message" />
</Button>
</Box>
);
}; |
Beta Was this translation helpful? Give feedback.
Hi @gyasi-eco
Thanks for coming to Office Hours, sorry it took a while to follow up here.
As we finally came to discover, it wasn't really a versioning problem, just a small implementation detail.
As a reminder, Any Lexical Plugin must be registered as a child of the editor, otherwise it doesn't have access to the editor context, which it will need if you want it to do something.
The
ClearEditorPlugin
is a fairly dumb component, in that all it really does is respond to a command being dis…