-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clipboard.js only works on click events #370
Comments
Hey @ddivecs, this is a very nice feature suggestion but unfortunately the browser has some limitations in what is considered a user interaction. My advice to you is to use Thanks again for your input! |
@zenorocha Hello, I'm very confused of this |
This works for me in Chrome and Safari today: /** Copies a string directly to the clipboard with a simulated button click. */
const copy = s => {
const dummyButton = document.createElement('button')
const clipboard = new ClipboardJS(dummyButton, { text: () => s })
dummyButton.click()
}
// copy on keydown
window.addEventListener('keydown', e => {
copy('Hello universe')
})
https://github.com/zenorocha/clipboard.js/wiki/Known-Limitations Seems to not be a problem for |
I understand that the clipboard api has security in place that requires user interaction and have read #127 and #189, but would it be possible to expand clipboard.js to work with other events besides
.click
(preferably, any arbitrary user event).Specifically, it is useful in my app to respond to the keydown and context menu events, but currently clipboard only lets us respond to clicks. Also in these cases I would like to unbind from the click event in clipboardjs. Essentially, our click events handle selection in a grid, but should not necessarily trigger copy. Other interactions in our application cause copy.
The text was updated successfully, but these errors were encountered: