react-draft-wysiwyg - Prevent drag and drop text if max-length exceed

Viewed 369

Is there a way to prevent drag and drop text from outside editor if length of editor text with dragged text exceed max-length I have tried using handleDrop event, but it accepts the parameters (SelectionState, dataTransfer, isInternal) I tried to get text from SelectionState object, but couldn't succeed

2 Answers

I have resolved above issue by using the event onEditorStateChange

 const onEditorStateChange = (editorState) => {
    const text =  editorState.getCurrentContent().getPlainText('')
    const lines = text ? text.split('\n') : 0

    if (lines.length <= 15 && text.length <= charLimit) {
      setEditorState(editorState)
    } else {
      return 'handled'
    }
  }
Related