zenorocha / clipboard.js

:scissors: Modern copy to clipboard. No Flash. Just 3kb gzipped :clipboard:
https://clipboardjs.com
MIT License
33.98k stars 3.98k forks source link

Enhance the container option #860

Open Sir-Genius opened 1 year ago

Sir-Genius commented 1 year ago

It would be fantastic if we could pass a function with a trigger as an argument to the container option:

const clipboard = new ClipboardJS('.js-copy', {
  container: trigger => trigger.closest('.modal')
});
titanism commented 10 months ago

Going to submit a pull request now for this.

titanism commented 10 months ago

Well, maybe not, forking isn't working, might be a GitHub outage

Screen Shot 2023-11-10 at 7 24 57 PM
titanism commented 10 months ago

Related https://github.com/zenorocha/clipboard.js/issues/855

titanism commented 10 months ago

Also see https://github.com/zenorocha/clipboard.js/issues/388#issuecomment-304713602

cderv commented 6 months ago

I believe this would help having one definition of new ClipboardJS('.copy-button', ...) to handle element that are or not in a modal.

Currently, it seems only one specific element can be passed to container - allowing a function would be like target or text and allow more flexibility

obetomuniz commented 2 months ago

Hey folks, there are some bugs that I will be contributing first to solve, but definitely, after them, I'll be considering all related proposals to triage and potentially work on them, okay? Thank you so much for proposing it.