From 11e88526c7ba98d77812ecc79c4584a3d70b7bfc Mon Sep 17 00:00:00 2001 From: Varun Date: Mon, 6 Apr 2026 19:16:04 +0530 Subject: [PATCH] fix: copy button in share assets fix Signed-off-by: Varun --- src/components/shared/ShareAssetsTrigger.tsx | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/components/shared/ShareAssetsTrigger.tsx b/src/components/shared/ShareAssetsTrigger.tsx index 31e05db..7d30545 100644 --- a/src/components/shared/ShareAssetsTrigger.tsx +++ b/src/components/shared/ShareAssetsTrigger.tsx @@ -40,13 +40,27 @@ export default function ShareAssetsTrigger({ filters, buttonProps }: ShareAssets }); } - const handleCopy = () => { - if (generatedLink) { - navigator.clipboard.writeText(generatedLink); + const handleCopy = async () => { + if (!generatedLink) return; + try { + if (navigator.clipboard && window.isSecureContext) { + await navigator.clipboard.writeText(generatedLink); + } else { + const textArea = document.createElement('textarea'); + textArea.value = generatedLink; + textArea.style.position = 'fixed'; + textArea.style.left = '-9999px'; + document.body.appendChild(textArea); + textArea.select(); + document.execCommand('copy'); + document.body.removeChild(textArea); + } setCopied(true); setTimeout(() => { setCopied(false); }, 2000); + } catch { + setErrorMessage('Failed to copy link'); } }