diff --git a/src/components/Editor/index.jsx b/src/components/Editor/index.jsx index f151ded6..95f17417 100644 --- a/src/components/Editor/index.jsx +++ b/src/components/Editor/index.jsx @@ -11,6 +11,7 @@ import { Label } from "neetoui"; import ErrorWrapper from "components/Common/ErrorWrapper"; import useEditorWarnings from "hooks/useEditorWarnings"; import "src/styles/editor/index.scss"; +import { removeEmptyTags } from "src/utils"; import { DEFAULT_EDITOR_OPTIONS } from "./constants"; import CharacterCountWrapper from "./CustomExtensions/CharacterCount"; @@ -107,6 +108,15 @@ const Editor = ( 100 ); + const handleBlur = props => { + const { editor } = props; + const trimmedContent = removeEmptyTags(editor.getHTML()); + + onChange(trimmedContent); + editor.commands.setContent(trimmedContent); + onBlur(props); + }; + const customExtensions = useCustomExtensions({ placeholder, extensions, @@ -169,7 +179,7 @@ const Editor = ( onCreate: ({ editor }) => !autoFocus && setInitialPosition(editor), onUpdate: debouncedOnChangeHandler, onFocus, - onBlur, + onBlur: handleBlur, }); useEditorState({