1
0
Fork 0
mirror of https://gitlab.com/bramw/baserow.git synced 2025-04-13 00:38:06 +00:00
bramw_baserow/web-frontend/modules/database/utils/clipboard.js
2020-05-25 15:50:47 +00:00

17 lines
488 B
JavaScript

/**
* Copies the given text to the clipboard by temporarily creating a textarea and
* using the documents `copy` command.
*/
export const copyToClipboard = (text) => {
const textarea = document.createElement('textarea')
document.body.appendChild(textarea)
textarea.style.position = 'absolute'
textarea.style.left = '-99999px'
textarea.style.top = '-99999px'
textarea.value = text
textarea.select()
document.execCommand('copy')
document.body.removeChild(textarea)
}