fallback to depracted copy text if clipboard api not available (#6200) (#6218)

pull/6221/head
zees-dev 3 years ago committed by GitHub
parent 4aea5690a8
commit 7cc28b10a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -32,7 +32,19 @@ export function CopyButton({
function onClick() {
// https://developer.mozilla.org/en-US/docs/Web/API/Clipboard
// https://caniuse.com/?search=clipboard
navigator.clipboard.writeText(copyText);
if (navigator.clipboard) {
navigator.clipboard.writeText(copyText);
} else {
// https://stackoverflow.com/a/57192718
const inputEl = document.createElement('input');
inputEl.value = copyText;
inputEl.type = 'text';
document.body.appendChild(inputEl);
inputEl.select();
document.execCommand('copy');
inputEl.type = 'hidden';
document.body.removeChild(inputEl);
}
setIsFading(true);
}

Loading…
Cancel
Save