Selaa lähdekoodia

fix: improved copy text helper function (#8677)

master
Calinteodor 4 vuotta sitten
vanhempi
commit
87a110b9c3
No account linked to committer's email address

+ 2
- 2
react/features/base/buttons/CopyButton.js Näytä tiedosto

2
 
2
 
3
 import React, { useState } from 'react';
3
 import React, { useState } from 'react';
4
 
4
 
5
-import { translate } from '../../base/i18n';
6
 import { Icon, IconCheck, IconCopy } from '../../base/icons';
5
 import { Icon, IconCheck, IconCopy } from '../../base/icons';
7
-import { copyText } from '../../base/util';
6
+import { translate } from '../i18n';
7
+import { copyText } from '../util';
8
 
8
 
9
 
9
 
10
 type Props = {
10
 type Props = {

+ 2
- 11
react/features/base/util/helpers.js Näytä tiedosto

31
  * @param {string} textToCopy - Text to be copied.
31
  * @param {string} textToCopy - Text to be copied.
32
  * @returns {boolean}
32
  * @returns {boolean}
33
  */
33
  */
34
-export function copyText(textToCopy: string) {
35
-    const fakeTextArea = document.createElement('textarea');
34
+export async function copyText(textToCopy: string) {
36
     let result;
35
     let result;
37
 
36
 
38
-    // $FlowFixMe
39
-    document.body.appendChild(fakeTextArea);
40
-    fakeTextArea.value = textToCopy;
41
-    fakeTextArea.select();
42
-
43
     try {
37
     try {
44
-        result = document.execCommand('copy');
38
+        result = await navigator.clipboard.writeText(textToCopy);
45
     } catch (err) {
39
     } catch (err) {
46
         result = false;
40
         result = false;
47
     }
41
     }
48
 
42
 
49
-    // $FlowFixMe
50
-    document.body.removeChild(fakeTextArea);
51
-
52
     return result;
43
     return result;
53
 }
44
 }
54
 
45
 

Loading…
Peruuta
Tallenna