Skip to content
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

[Feature Request] Add ability to listen for transition events on v-dialog #6504

Closed
rdsn opened this issue Feb 15, 2019 · 13 comments
Closed

[Feature Request] Add ability to listen for transition events on v-dialog #6504

rdsn opened this issue Feb 15, 2019 · 13 comments
Labels
C: VDialog VDialog maybe Functionality that we are considering T: feature A new feature

Comments

@rdsn
Copy link

rdsn commented Feb 15, 2019

Problem to solve

Sometimes it is needed to run some code when v-dialog closes but do it only after closing animation ends, the problem is that at the moment there seems to be no way to determine when it ends.

Proposed solution

A possible solution would be to pass $listeners from v-dialog to the transition component. E.g.

if (this.transition) {
  dialog = h('transition', {
    on: this.$listeners,
    props: {
      name: this.transition,
      origin: this.origin
    }
  }, [dialog]);
}

So that it could be used like this:

<v-dialog v-model="isDialogActive" width="500" @after-leave="runSomeCode">
@johnleider johnleider added the maybe Functionality that we are considering label Feb 15, 2019
@johnleider johnleider added this to the v2.x.x milestone Feb 15, 2019
@KaelWD KaelWD added the T: feature A new feature label Nov 6, 2019
@KaelWD
Copy link
Member

KaelWD commented Nov 6, 2019

Related: #5516

@b-strauss
Copy link

Use this function to patch the original component and forward the $listeners object.

import {VDialog as VDialogOriginal} from 'vuetify/lib';

/**
 * Hack to patch VDialog because it has no way to set transition hooks
 */
function patchVDialog (VDialog) {
  const ExtendedVDialog = VDialog.extend({});
  const originalRender = ExtendedVDialog.prototype.constructor.options.render;

  ExtendedVDialog.prototype.constructor.options.render = function (h) {
    const originalH = h;
    h = (...args) => {
      // Check for the call to render a transition,
      // there is only one rendered transition in VDialog
      if (args[0] === 'transition') {
        // Forward the user provided listeners to the transition component
        args[1].on = this.$listeners;
      }

      return originalH(...args);
    };
    return originalRender.call(this, h);
  };

  return ExtendedVDialog;
}

// This can be used now in place of the original.
const VDialog = patchVDialog(VDialogOriginal);

@brunlid
Copy link

brunlid commented May 7, 2020

Any news on when there will be working transition hooks for v-dialog? I cannot get any of transitionend or after-enter to trigger. Thank you

@flyingL123
Copy link

Trying to figure out the status of this? Should it be working at this point or it's not implemented? I am not having any luck using transition callbacks on v-dialog.

@flyingL123
Copy link

In my case I need this functionality to properly set the width of an element that is part of the dialog content. It depends on the width of other elements in there, and I can't simply set it as soon as the dialog's model value changes because the content is not yet fully rendered as it is transitioning in.

@nclemeur
Copy link

nclemeur commented Jul 1, 2020

I agree that this would be useful. I have the same use case as @flyingL123 with a SVG drawing that needs to be updated with the correct size. Currently I am doing this with a setTimeout, but this is a bit ugly.

@LZQCN
Copy link

LZQCN commented Jul 8, 2020

Temporary solution:
v-snackbar

watch: {
  value(newValue, oldValue) {
    if (!newValue && oldValue) {
      snackbarEl.addEventListener('transitionend', () => {
        // code
      }, { once: true });
    }
  },
}

v-dialog

setTimeout(() => {
  // code
}, 300);

@gustavosbarreto
Copy link

Use this function to patch the original component and forward the $listeners object.

import {VDialog as VDialogOriginal} from 'vuetify/lib';

/**
 * Hack to patch VDialog because it has no way to set transition hooks
 */
function patchVDialog (VDialog) {
  const ExtendedVDialog = VDialog.extend({});
  const originalRender = ExtendedVDialog.prototype.constructor.options.render;

  ExtendedVDialog.prototype.constructor.options.render = function (h) {
    const originalH = h;
    h = (...args) => {
      // Check for the call to render a transition,
      // there is only one rendered transition in VDialog
      if (args[0] === 'transition') {
        // Forward the user provided listeners to the transition component
        args[1].on = this.$listeners;
      }

      return originalH(...args);
    };
    return originalRender.call(this, h);
  };

  return ExtendedVDialog;
}

// This can be used now in place of the original.
const VDialog = patchVDialog(VDialogOriginal);

@b-strauss Can you give a complete example of using this hack?

@b-strauss
Copy link

b-strauss commented Jul 9, 2020

@gustavosbarreto

you need to include the patched VDialog to use inside your template

const VDialog = patchVDialog(VDialogOriginal);

export default {
  components: {
    VDialog,
  },
};

Then in the template just add your listeners to the patched component.

<v-dialog @after-enter=""></v-dialog>

@alekstar79
Copy link

alekstar79 commented Nov 26, 2021

@gustavosbarreto

you need to include the patched VDialog to use inside your template

const VDialog = patchVDialog(VDialogOriginal);

export default {
components: {
VDialog,
},
};

Then in the template just add your listeners to the patched component.

<v-dialog @after-enter="">

Vuetify 2.5.10 patch does not work. I looked at the sources and implemented a working patch

import { VDialog as VDialogOriginal } from 'vuetify/lib'

function patchVDialog(VDialog)
{
    return VDialog.extend({
        methods: {
            genTransition()
            {
                const content = this.genInnerContent()

                if (!this.transition) return content

                return this.$createElement('transition', {
                    on: this.$listeners,
                    props: {
                        name: this.transition,
                        origin: this.origin,
                        appear: true
                    }

                }, [content])
            }
        }
    })
}
export const VDialogPatched = patchVDialog(VDialogOriginal)

@sk8killer
Copy link

@alekstar79 this doesn't work... can't catch @leave-enter...

@charlesg99
Copy link

I was reading the documentation to find this exact behavior and it isn't mentioned. Glad I can do it as @after-leave works on the v-dialog element, but it would be nice to add thoses events to the api page.

johnleider added a commit that referenced this issue Apr 4, 2024
@johnleider
Copy link
Member

I was reading the documentation to find this exact behavior and it isn't mentioned. Glad I can do it as @after-leave works on the v-dialog element, but it would be nice to add thoses events to the api page.

I've added information regarding the events in 8083d89

image

johnleider added a commit to vstyler96/vuetify that referenced this issue Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: VDialog VDialog maybe Functionality that we are considering T: feature A new feature
Projects
None yet
Development

No branches or pull requests