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

Any way to close currently open dialog on route change? #111

Open
disjointed opened this issue Nov 11, 2020 · 1 comment
Open

Any way to close currently open dialog on route change? #111

disjointed opened this issue Nov 11, 2020 · 1 comment

Comments

@disjointed
Copy link

disjointed commented Nov 11, 2020

Say I have opened some persistent dialog with this.$dialog.showAndWait() and then accidentally press "back" in the browser or on my mouse (the side buttons) -- the route changes to the previous one, but the dialog won't close an is still on the screen. Is there any programmatic, "native" way to handle this situation and close the dialog on route change?

Right now I'm doing it like this:

watch: {
	'$route.fullPath' (value) {
		this.$emit('submit', false);
	},
},

from inside the dialog's component.

Or maybe there's some global method to close all open dialogs?

Thank you.

@AbdelrhmanAbdelhamed
Copy link
Contributor

Duplicate of #64 Clear all dialogs and notifications

I managed to do it using the shown and destroyed events to keep track of the dialogs.

    let _dialogs = []

    Vue.prototype.$dialog.on('shown', ({ dialog }) => _dialogs.push(dialog))

    Vue.prototype.$dialog.on(
      'destroyed',
      ({ dialog }) => (_dialogs = _dialogs.filter((_dialog) => _dialog.id !== dialog.id))
    )

    Vue.prototype.$dialog.clearDialogs = () => {
      _dialogs.forEach((_dialog) => _dialog.remove())
      _dialogs = []
    }

   // Then you can call this.$dialog.clearDialogs() inside any component

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants