mirror of
https://github.com/apache/superset.git
synced 2026-04-23 18:14:56 +00:00
Switched to span instead of textarea for copytoclipboard (#3923)
This commit is contained in:
committed by
Maxime Beauchemin
parent
ed85032277
commit
5466fab2a0
@@ -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');
|
||||
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';
|
||||
|
||||
textArea.style.position = 'fixed';
|
||||
textArea.style.left = '-1000px';
|
||||
textArea.value = textToCopy;
|
||||
|
||||
document.body.appendChild(textArea);
|
||||
range.selectNode(textArea);
|
||||
document.body.appendChild(span);
|
||||
range.selectNode(span);
|
||||
selection.addRange(range);
|
||||
try {
|
||||
if (!document.execCommand('copy')) {
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user