Browse Source

fix copy button

Signed-off-by: shanghaikid <jiangruiyi@gmail.com>
shanghaikid 2 years ago
parent
commit
bfe975a144
1 changed files with 5 additions and 5 deletions
  1. 5 5
      client/src/components/advancedSearch/CopyButton.tsx

+ 5 - 5
client/src/components/advancedSearch/CopyButton.tsx

@@ -13,9 +13,9 @@ const CopyButton: FC<CopyButtonProps> = props => {
   const { t: commonTrans } = useTranslation();
   const { t: commonTrans } = useTranslation();
   const copyTrans = commonTrans('copy');
   const copyTrans = commonTrans('copy');
   const [tooltipTitle, setTooltipTitle] = useState('Copy');
   const [tooltipTitle, setTooltipTitle] = useState('Copy');
-  
+
   const unsecuredCopyToClipboard = (v: string) => {
   const unsecuredCopyToClipboard = (v: string) => {
-    const textArea = document.createElement("textarea");
+    const textArea = document.createElement('textarea');
     textArea.style.position = 'fixed';
     textArea.style.position = 'fixed';
     textArea.style.opacity = '0';
     textArea.style.opacity = '0';
     textArea.style.zIndex = '-1000';
     textArea.style.zIndex = '-1000';
@@ -29,13 +29,13 @@ const CopyButton: FC<CopyButtonProps> = props => {
       console.error('Unable to copy to clipboard', err);
       console.error('Unable to copy to clipboard', err);
     }
     }
     document.body.removeChild(textArea);
     document.body.removeChild(textArea);
-  }
-  
+  };
+
   const handleClick = (event: React.MouseEvent<HTMLElement>, v: string) => {
   const handleClick = (event: React.MouseEvent<HTMLElement>, v: string) => {
     event.stopPropagation();
     event.stopPropagation();
 
 
     setTooltipTitle(copyTrans.copied);
     setTooltipTitle(copyTrans.copied);
-    (navigator.clipboard?.writeText ?? unsecuredCopyToClipboard)?.(v);
+    navigator.clipboard?.writeText(v) ?? unsecuredCopyToClipboard(v);
     setTimeout(() => {
     setTimeout(() => {
       setTooltipTitle(copyTrans.copy);
       setTooltipTitle(copyTrans.copy);
     }, 1000);
     }, 1000);