Skip to content

Commit 63dfeea

Browse files
committed
Trim leading and trailing whitespaces on blur
1 parent 801c95d commit 63dfeea

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Diff for: src/components/Editor/index.jsx

+10-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Label } from "neetoui";
1111
import ErrorWrapper from "components/Common/ErrorWrapper";
1212
import useEditorWarnings from "hooks/useEditorWarnings";
1313
import "src/styles/editor/index.scss";
14+
import { removeEmptyTags } from "src/utils";
1415

1516
import { DEFAULT_EDITOR_OPTIONS } from "./constants";
1617
import CharacterCountWrapper from "./CustomExtensions/CharacterCount";
@@ -107,6 +108,14 @@ const Editor = (
107108
100
108109
);
109110

111+
const handleBlur = props => {
112+
const { editor } = props;
113+
const trimmedContent = removeEmptyTags(editor.getHTML());
114+
115+
onChange(trimmedContent);
116+
onBlur(props);
117+
};
118+
110119
const customExtensions = useCustomExtensions({
111120
placeholder,
112121
extensions,
@@ -169,7 +178,7 @@ const Editor = (
169178
onCreate: ({ editor }) => !autoFocus && setInitialPosition(editor),
170179
onUpdate: debouncedOnChangeHandler,
171180
onFocus,
172-
onBlur,
181+
onBlur: handleBlur,
173182
});
174183

175184
useEditorState({

0 commit comments

Comments
 (0)