https://github.com/posva/clipboard-text
Simple and small copy-text-to-the-clipboard-utility with IE11 support
https://github.com/posva/clipboard-text
browser clipboard copy text
Last synced: 9 months ago
JSON representation
Simple and small copy-text-to-the-clipboard-utility with IE11 support
- Host: GitHub
- URL: https://github.com/posva/clipboard-text
- Owner: posva
- License: other
- Created: 2019-07-23T10:30:42.000Z (almost 7 years ago)
- Default Branch: main
- Last Pushed: 2024-10-14T03:58:57.000Z (over 1 year ago)
- Last Synced: 2024-10-17T00:12:36.599Z (over 1 year ago)
- Topics: browser, clipboard, copy, text
- Language: TypeScript
- Size: 130 KB
- Stars: 13
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Funding: .github/funding.yml
- License: LICENSE
Awesome Lists containing this project
README
# clipboard-text [](https://github.com/posva/clipboard-text/actions/workflows/test.yml) [](https://www.npmjs.com/package/clipboard-text)
> Simple and small copy-text-to-the-clipboard-utility with IE11 support
## Installation
```sh
npm install clipboard-text
```
## Usage
```js
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
- [copy-text-to-clipboard](https://github.com/sindresorhus/copy-text-to-clipboard) -
Original package with no support for IE and no support for focus traps
## License
[MIT](http://opensource.org/licenses/MIT)