react-json-editor-ajrm icon indicating copy to clipboard operation
react-json-editor-ajrm copied to clipboard

Paste is prevented when using React Portals (new window)

Open mpeula opened this issue 4 years ago • 0 comments

  1. What version of RJEA are you using (react-json-editor-ajrm version)? *REQUIRED

2.5.13

  1. What operating system and processor architecture are you using? *REQUIRED

Windows 10 Pro 64 bits

  1. What did you do? *REQUIRED

I pasted a piece of json in one line.

  1. What did you expect to see? *REQUIRED

The content added to the json

  1. What did you see instead? *REQUIRED

No content has been added to the json

  1. Summary

The project I'm working on uses this component inside a React Portal, portals can be created inside the same document, but there are ways to create portals in new browser windows.

I have detected that the piece of code that is causing this issue is this one, and looks like:

onPaste(event){
    if (this.props.viewOnly) {
        this.stopEvent(event);
    } else {
        event.preventDefault();
        var text = event.clipboardData.getData('text/plain');
        document.execCommand('insertText', false, text);
    }
    this.update();
}

The problem is that the document is refering to is no longer the document when the component is placed, that's why it does not do anything at all.

I have modified my local library and it's working fine with this code:

onPaste(event){
    if (this.props.viewOnly) {
        this.stopEvent(event);
    }
     this.update();
}

mpeula avatar Feb 26 '21 12:02 mpeula