File tree Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import React from 'react';
2
2
3
3
import { toType } from './../helpers/util' ;
4
4
5
- //clibboard icon
5
+ //clipboard icon
6
6
import { Clippy } from './icons' ;
7
7
8
8
//theme
@@ -26,20 +26,23 @@ export default class extends React.PureComponent {
26
26
}
27
27
28
28
handleCopy = ( ) => {
29
- const container = document . createElement ( 'textarea' ) ;
30
29
const { clickCallback, src, namespace } = this . props ;
31
30
32
- container . innerHTML = JSON . stringify (
31
+ const textToCopy = JSON . stringify (
33
32
this . clipboardValue ( src ) ,
34
33
null ,
35
34
' '
36
35
) ;
37
36
38
- document . body . appendChild ( container ) ;
39
- container . select ( ) ;
40
- document . execCommand ( 'copy' ) ;
41
-
42
- document . body . removeChild ( container ) ;
37
+ if ( navigator . clipboard ) {
38
+ await navigator . clipboard . writeText ( textToCopy ) ;
39
+ } else {
40
+ console . error (
41
+ 'react-json-view error:' ,
42
+ 'navigator.clipboard not supported by this browser'
43
+ ) ;
44
+ return ;
45
+ } ;
43
46
44
47
this . copiedTimer = setTimeout ( ( ) => {
45
48
this . setState ( {
You can’t perform that action at this time.
0 commit comments