From 82aad21900c7bcc7f48a0455e0aed79bf50fd984 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 25 Aug 2022 21:28:20 -0500 Subject: [PATCH] CopyableInput: oh yeah, make the input actually copy --- app/soapbox/components/copyable-input.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/soapbox/components/copyable-input.tsx b/app/soapbox/components/copyable-input.tsx index 4a42452bb..c38cc8c5b 100644 --- a/app/soapbox/components/copyable-input.tsx +++ b/app/soapbox/components/copyable-input.tsx @@ -5,7 +5,7 @@ import { Button, HStack, Input } from './ui'; interface ICopyableInput { /** Text to be copied. */ - value?: string, + value: string, } /** An input with copy abilities. */ @@ -14,6 +14,12 @@ const CopyableInput: React.FC = ({ value }) => { const selectInput = () => { input.current?.select(); + + if (navigator.clipboard) { + navigator.clipboard.writeText(value); + } else { + document.execCommand('copy'); + } }; return (