1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-25 08:19:40 +02:00

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

This commit is contained in:
zees-dev 2021-12-06 10:01:54 +13:00 committed by GitHub
parent 4aea5690a8
commit 7cc28b10a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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);
}