vue-clipboard2 icon indicating copy to clipboard operation
vue-clipboard2 copied to clipboard

not work on vuetify dialog

Open jazuly opened this issue 4 years ago • 8 comments

im not sure but when i try, it not work on vuetify dialog

jazuly avatar Oct 18 '20 14:10 jazuly

Having the same issue since a while back. Which version of vuetify are you on?

billerby avatar Oct 22 '20 10:10 billerby

the latest one..

jazuly avatar Oct 22 '20 23:10 jazuly

Well this is fixed in #23 you have to provide a container to make it work on modals.

billerby avatar Oct 23 '20 12:10 billerby

Use container option if you're inside Vuetify dialog.

const container = document.querySelector('.v-dialog');

this.$copyText('Your text here', container).then(() => {
     this.snackbar = true;
});

orkhan-huseyn avatar Nov 04 '20 05:11 orkhan-huseyn

Use this config, it's work.

import VueClipboard from 'vue-clipboard2';
VueClipboard.config.autoSetContainer = true;
Vue.use(VueClipboard);

ziqq avatar Nov 13 '20 06:11 ziqq

Use container option if you're inside Vuetify dialog.

const container = document.querySelector('.v-dialog');

this.$copyText('Your text here', container).then(() => {
     this.snackbar = true;
});

This worked for me. I am able to use a v-btn inside a v-dialog, and the contents of the clipboard are correct when I paste into a text doc.

Use this config, it's work.

import VueClipboard from 'vue-clipboard2';
VueClipboard.config.autoSetContainer = true;
Vue.use(VueClipboard);

This did not. My v-btn inside the v-dialog fires, the $copyText function fires, but the clipboard does not get updated.

alfreema avatar Nov 16 '20 16:11 alfreema

Looking at the source, the option autoSetContainer is only passed down to vue directive not to the instance prototype function $copyText.

https://github.com/Inndy/vue-clipboard2/blob/8a542c558c6857212d06f6fc1929384a5b5104cc/vue-clipboard.js#L3-L18

This makes sense, because as an imperative API, it seems to me that you can't infer the container automagically, since the function can be called anywhere — EDIT: that being said, documentation could explicit about it.

So in addendum to @alfreema @orkhan-huseyn answers for the container option:

  • using a vue ref, tike this.$refs.dialog instead of querySelector might be more vue-ish.
  • using this.$el would also be a good candidate for dialogs (if the function is being called within).

Cheers!

renatodeleao avatar Nov 26 '20 17:11 renatodeleao

If the parent component is a "v-dialog", maybe you can add a tag like " copySelect=".v-dialog"" in the parent component, then pass the value to the child component. In the child component, code likes the follow. `let container = document.querySelector(this.copySelect);

this.$copyText('Your text', container).then(() => { });`

Microhawk avatar Jan 12 '21 10:01 Microhawk