1 export default function textToClipboard(text = '', target = document.body) {
2 const oldActiveElement = document.activeElement as HTMLElement;
3 if (navigator.clipboard) {
4 void navigator.clipboard.writeText(text);
6 const dummy = document.createElement('textarea');
7 target.appendChild(dummy);
10 document.execCommand('copy');
11 target.removeChild(dummy);
13 oldActiveElement?.focus?.();