Part II of a new major release proposal #516
Current state
new Clipboard('.btn', {
text: function(trigger) {
return 'blah blah';
}
});
Proposal
button.addEventListener('click', () => {
clipboard.copy('blah blah')
})
Benefits
Today a click event listener is created inside the library in order to facilitate usage. The problem is that attaching an event to the DOM might not be a good idea when using Angular, React, Vue, etc
The benefits of this approach is that users can call a copy/cut function independently inside their own event listeners.
Drawbacks
Users will need to know that an event listener is necessary, otherwise it will not work.
Related
got it. thank you very much.
I think the drawback is not a big problem since we can mention this in the documentation. The huge DOM-independent advantage outweighs this.
Also, the api to handle success and error should be refined. How about having it throwing error when attempt to copy to clipboard fails?
@hoangmngo error handling is being mentioned here #517
Users will need to know that an event listener is necessary, otherwise it will not work.
That's why we have a Readme 馃槂
So there's no way to do it at the moment?
There is a way, but browser support is very limited.
https://caniuse.com/#search=clipboard
I'm tracking the status of the implementation as soon as it lands on other major browsers, I'll update the library to address this use case.
It seems that all the major browsers allow triggering copy events inside a event handler, but not paste events.
https://jsbin.com/huhekiqope/1/edit?html,js,console,output
Click on Copy button will correctly copy the data in clipboard, while click on Paste will not trigger paste event. Using Ctrl+v will trigger the event correctly.
Can't you just expose ClipboardAction for importing and let users do it themselves?