forked from coracle/flotilla
16 lines
359 B
TypeScript
16 lines
359 B
TypeScript
export const copyToClipboard = (text: string) => {
|
|
const {activeElement} = document
|
|
const input = document.createElement("textarea")
|
|
|
|
input.innerHTML = text
|
|
document.body.appendChild(input)
|
|
input.select()
|
|
|
|
const result = document.execCommand("copy")
|
|
|
|
document.body.removeChild(input)
|
|
;(activeElement as HTMLElement).focus()
|
|
|
|
return result
|
|
}
|