Skip to content

Commit

Permalink
Simplify copyToClipboard util
Browse files Browse the repository at this point in the history
All supported browsers now provide access to the clipboard API
via `navigator.clipboard` so we no longer need to use workarounds
involving textareas etc.
  • Loading branch information
AlanGreene authored and tekton-robot committed Oct 3, 2022
1 parent eb21d4d commit a9d77c5
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions packages/utils/src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,7 @@ export function classNames(...args) {

/* 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) {
Expand Down

0 comments on commit a9d77c5

Please sign in to comment.