react-json-editor-ajrm
react-json-editor-ajrm copied to clipboard
Paste is prevented when using React Portals (new window)
- What version of RJEA are you using (react-json-editor-ajrm version)? *REQUIRED
2.5.13
- What operating system and processor architecture are you using? *REQUIRED
Windows 10 Pro 64 bits
- What did you do? *REQUIRED
I pasted a piece of json in one line.
- What did you expect to see? *REQUIRED
The content added to the json
- What did you see instead? *REQUIRED
No content has been added to the json
- 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();
}