Draft-js: handlePastedText - returning true or false has no impact on editor

Created on 25 Jan 2017  路  8Comments  路  Source: facebook/draft-js

I'm not sure what the problem is but the return from handlePastedText has no impact on the editor. On paste, I'm able to insert an entity using the handlePastedText handler but even though I return true I can't prevent the default pasted text.

By returning "true" I was expecting nothing to be pasted into the editor. Am I wrong?

bug needs more info

Most helpful comment

Returning 'handled' or true should work. If it doesn't, can you post a fiddle where it's not working?

All 8 comments

Returning 'handled' or true should work. If it doesn't, can you post a fiddle where it's not working?

The same problem here. Copying Hyperlink from text editor and pasting inside Draftjs editor output nothing.
https://jsfiddle.net/Budaa/2d1wacc9/2/

@Budaa What is that fiddle supposed to show?

From docs.

Handle text and html(for rich text) that has been pasted directly into the editor. Returning true will prevent the default paste behavior.

If I'm understanding this correct it should remove all information, except plaintext from pasted content. As the default is stripPastedStyles={false}

Yes, setting stripPastedStyles={true}, will remove everything except plaintext when pasting. This issue however, was about handlePastedText not functioning according to its specification (although I think it does).

Just to clarify:
If you return 'handled' or true from handlePastedText, _nothing should happen_, since what you're essentially doing is telling Draft that you have taken care of the paste instead.

@lucidlive, do you have a jsfiddle with a repro?

Looks like this may be stale, and we need more info in order to reproduce the bug. Closing for now, feel free to reopen if this is still a problem.

Still seeing the issue here:

handlePastedText(text, html) {
  this.setState({
    editorState: EditorState.push(
      this.state.editorState,
      ContentState.createFromText('testing'),
      'paste-text',
    ),
  });
  return true;
}

// ...

<Editor
  blockRendererFn={this.renderBlock}
  editorState={editorState}
  handleKeyCommand={this.handleKeyCommand}
  handlePastedText={this.handlePastedText}
  keyBindingFn={keyBindingFn}
  onChange={this.handleChange}
/>

According to the docs, no matter what I paste into my editor, it should just add "testing" right? This is not working currently and whatever I paste into the editor shows up.

Was this page helpful?
0 / 5 - 0 ratings