Skip to content

Instantly share code, notes, and snippets.

@cameronp98
Last active May 29, 2020 18:15
Show Gist options
  • Save cameronp98/fac7954037246c19a077cf85aadeb0ff to your computer and use it in GitHub Desktop.
Save cameronp98/fac7954037246c19a077cf85aadeb0ff to your computer and use it in GitHub Desktop.
Copy Input, requires semantic-ui-react semantic-ui-css
import React from 'react'
import { Button, Input } from 'semantic-ui-react'
function CopyInput({ value, label }) {
const input = React.createRef()
function handleClick() {
input.current.select()
// input.current.setSelectionRange(0, 99999)
document.execCommand('copy')
}
return (
<Input
labelPosition='right'
ref={input}
readOnly
value={value}
label={<Button onClick={handleClick} content={label} icon='copy' />}
/>
)
}
export default CopyInput
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment