🐛 Fixed copy-to-clipboard buttons in Chrome + Firefox

no issue

- the method we used for copying text to the clipboard for older browsers has broken on some newer browsers
- the more modern `navigator.clipboard.writeText` API is now universally supported by our target browsers so we're able to switch to that instead which is working across the board
This commit is contained in:
Kevin Ansfield 2021-10-05 15:32:23 +01:00
parent a15cc41f03
commit 6155645a45

View File

@ -1,11 +1,3 @@
export default function copyTextToClipboard(text) {
let textarea = document.createElement('textarea');
textarea.value = text;
textarea.setAttribute('readonly', '');
textarea.style.position = 'absolute';
textarea.style.left = '-9999px';
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
navigator.clipboard.writeText(text);
}