From 29b5299fe90f8e6000837f0050270afebd8f729d Mon Sep 17 00:00:00 2001 From: Alan Greene Date: Sat, 1 Oct 2022 21:31:09 +0100 Subject: [PATCH] Simplify `copyToClipboard` util All supported browsers now provide access to the clipboard API via `navigator.clipboard` so we no longer need to use workarounds involving textareas etc. --- packages/utils/src/utils/index.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/packages/utils/src/utils/index.js b/packages/utils/src/utils/index.js index 0f73d191a..8aa0a3ffb 100644 --- a/packages/utils/src/utils/index.js +++ b/packages/utils/src/utils/index.js @@ -23,15 +23,7 @@ export const ALL_NAMESPACES = '*'; /* istanbul ignore next */ export const copyToClipboard = text => { - const input = document.createElement('textarea'); - input.value = text; - input.setAttribute('readonly', ''); - input.style.position = 'absolute'; - input.style.top = '-9999px'; - document.body.appendChild(input); - input.select(); - document.execCommand('copy'); - document.body.removeChild(input); + navigator.clipboard?.writeText(text); }; export function getErrorMessage(error) {