Merge branch 'crypto-log-webcrypto-rsa-signing-support' into 'main'
[ProtonMail-WebClient.git] / applications / pdf-ui / src / textToClipboard.ts
blobc59155842422a125b7ae2f7d36f24bccd0f58866
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);
5     } else {
6         const dummy = document.createElement('textarea');
7         target.appendChild(dummy);
8         dummy.value = text;
9         dummy.select();
10         document.execCommand('copy');
11         target.removeChild(dummy);
12     }
13     oldActiveElement?.focus?.();