diff --git a/src/MUIRichTextEditor.tsx b/src/MUIRichTextEditor.tsx index 6f87b7b..a4a0aba 100644 --- a/src/MUIRichTextEditor.tsx +++ b/src/MUIRichTextEditor.tsx @@ -489,7 +489,7 @@ const MUIRichTextEditor: RefForwardingComponent { + const handleBeforeInput = (chars: string, editorState: EditorState): DraftHandleValue => { if (chars === " " && searchTerm.length) { clearSearch() } else if (autocompleteSelectionStateRef.current) { @@ -501,8 +501,7 @@ const MUIRichTextEditor: RefForwardingComponent { @@ -745,8 +744,16 @@ const MUIRichTextEditor: RefForwardingComponent { + return isMaxLengthHandled(editorState, text.length) + } + + const handleReturn = (_e: any, editorState: EditorState): DraftHandleValue => { + return isMaxLengthHandled(editorState, 1) + } + + const isMaxLengthHandled = (editorState: EditorState, nextLength: number): DraftHandleValue => { const currentLength = editorState.getCurrentContent().getPlainText('').length - return isGreaterThan(currentLength + text.length, props.maxLength) ? "handled" : "not-handled" + return isGreaterThan(currentLength + nextLength, props.maxLength) ? "handled" : "not-handled" } const toggleMouseUpListener = (addAfter = false) => { @@ -1074,6 +1081,7 @@ const MUIRichTextEditor: RefForwardingComponent