Skip to content

Commit

Permalink
Switched to span instead of textarea for copytoclipboard (apache#3923)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mogball authored and michellethomas committed May 23, 2018
1 parent 4e29257 commit 8121a0e
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions superset/assets/javascripts/components/CopyToClipboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,16 @@ export default class CopyToClipboard extends React.Component {
selection.removeAllRanges();
document.activeElement.blur();
const range = document.createRange();
const textArea = document.createElement('textarea');

textArea.style.position = 'fixed';
textArea.style.left = '-1000px';
textArea.value = textToCopy;

document.body.appendChild(textArea);
range.selectNode(textArea);
const span = document.createElement('span');
span.textContent = textToCopy;
span.style.all = 'unset';
span.style.position = 'fixed';
span.style.top = 0;
span.style.clip = 'rect(0, 0, 0, 0)';
span.style.whiteSpace = 'pre';

document.body.appendChild(span);
range.selectNode(span);
selection.addRange(range);
try {
if (!document.execCommand('copy')) {
Expand All @@ -73,7 +75,7 @@ export default class CopyToClipboard extends React.Component {
window.alert(t('Sorry, your browser does not support copying. Use Ctrl / Cmd + C!')); // eslint-disable-line
}

document.body.removeChild(textArea);
document.body.removeChild(span);
if (selection.removeRange) {
selection.removeRange(range);
} else {
Expand Down

0 comments on commit 8121a0e

Please sign in to comment.