clipboard-text
Simple and small copy-text-to-the-clipboard-utility with IE11 support
Installation
npm install clipboard-text
Usage
import copy from 'clipboard-text'
button.addEventListener('click', () => {
copy('Hi there')
})
API
copy(text: string, parentElement?: Element): boolean
Copy text
to the clipboard.
If the event triggering the copy
functions comes from an element with a focus
trap, like a Modal, you will need to provide a parentElement
. By default,
parentElement
is set to body
.
Returns a boolean of whether it succeeded to copy the text.
Must be called in response to a user gesture event, like click or keyup.
Related
License
MIT