Fix copy to clipboard in Safari 10
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import browser from './browser';
|
||||
|
||||
/**
|
||||
* Copies text to the clipboard using the textarea.
|
||||
* @param {string} text - Text to copy.
|
||||
@@ -8,7 +10,20 @@ function textAreaCopy(text) {
|
||||
textArea.value = text;
|
||||
document.body.appendChild(textArea);
|
||||
textArea.focus();
|
||||
textArea.select();
|
||||
|
||||
// iOS 13.4 supports Clipboard.writeText (https://stackoverflow.com/a/61868028)
|
||||
if (browser.iOS && browser.iOSVersion < 13.4) {
|
||||
// https://stackoverflow.com/a/46858939
|
||||
|
||||
const range = document.createRange();
|
||||
range.selectNodeContents(textArea);
|
||||
const selection = window.getSelection();
|
||||
selection.removeAllRanges();
|
||||
selection.addRange(range);
|
||||
textArea.setSelectionRange(0, 999999);
|
||||
} else {
|
||||
textArea.select();
|
||||
}
|
||||
|
||||
let ret;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user