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

[Enhancement] close VDialog when pressing the back button #1793

Closed
xmorell opened this issue Sep 18, 2017 · 27 comments · Fixed by #13756
Closed

[Enhancement] close VDialog when pressing the back button #1793

xmorell opened this issue Sep 18, 2017 · 27 comments · Fixed by #13756
Assignees
Labels
C: VDialog VDialog T: feature A new feature
Milestone

Comments

@xmorell
Copy link

xmorell commented Sep 18, 2017

Steps to reproduce

Open a dialog using a mobile.

Versions

All the versions, never been implemented

What is expected ?

I would expect that when the users click the back button from the mobile the opened dialog closes, instead of reloading the previous page.

What is actually happening ?

Actually if the users click the back button, the previous page is reload

Reproduction Link

https://vuetifyjs.com/components/dialogs

@johnleider johnleider added pending review The issue is still pending disposition T: enhancement Functionality that enhances existing features and removed pending review The issue is still pending disposition labels Sep 18, 2017
@FabianSilva
Copy link

FabianSilva commented Dec 21, 2017

I also noted this too... I'm thinking on make a route and go to that route that makes dialog open and come back to route with dialog closed....but reading https://router.vuejs.org/en/advanced/navigation-guards.html not sure if beforeRouteLeave can be used to check if dialog is open and close it and cancel going back...

update:
effectively, with the beforeRouteLeave event on the component I can avoid to go back if popup is open

something like this:

export default {
     ...
    beforeRouteLeave (to, from, next) {
      // called when the route that renders this component is about to be navigated away from.
      // has access to `this` component instance.
      if (this.popupVisible && !this.$store.state.drawer) {
        this.popupVisible = false
        next(false)
      } else {
        next()
      }

    },....

note: tested on browser... but I suppose that same will work for mobile too

@johnleider johnleider added this to the v1.2.x milestone Jan 6, 2018
@ksankumar
Copy link

ksankumar commented Jan 24, 2018

This issue should applicable for v-select, v-date and time picker modal, navigation bar, menus, bottom sheets in mobile

@ghost

This comment has been minimized.

@KaelWD KaelWD modified the milestones: v1.2.0, v1.4.0 Jul 31, 2018
@amritk

This comment has been minimized.

@scriptcoded

This comment has been minimized.

@ghost
Copy link

ghost commented Sep 13, 2018

If this is added, then I'd like to suggest that at least for v-dialog this behavior is not restricted to mobile only. Not sure if it happens to others, but to me it happens on desktop too often as well that I'm presented with a full screen dialog that could have very well been an entirely new page and when I press the Back button, I'm not where I expected.

@johnleider
Copy link
Member

This is still something we plan to implement but did not make the cut for v2.0 release.

If you have any additional questions, please reach out to us in our Discord community.

@johnleider johnleider modified the milestones: v2.0.0, v2.x.x Jun 26, 2019
@AndrewLamYW

This comment has been minimized.

@clementmas

This comment has been minimized.

@xmorell

This comment has been minimized.

@johnleider johnleider removed this from the v2.x.x milestone Jan 19, 2020
@tamirvs
Copy link

tamirvs commented Feb 11, 2020

I've created a mixin to solve this until a proper solution is given:
https://gist.github.com/tamirvs/d1a584f3fc9c494cf75d3ca76c54fb1b

@tamirvs
Copy link

tamirvs commented Feb 13, 2020

@mariusvigariu It could work, but if I have a navigation drawer that can be opened in every route I will have to create a special sub route in every route right?

@ghost
Copy link

ghost commented Feb 13, 2020

Yes, you are right. While for dialogs I would've nothing against creating an extra nuxt page, the drawers would be annoying to be handled like this.

@franciscouemura
Copy link

Hi, @tamirvs. The mixin solution is realy great. But it doesn't work when you have no history. I mean, if you have just landed on the page and then open the dialog and press back, it will leave the page. Have you noticed this? if yes, how do you treat this behavior?

@tamirvs

This comment has been minimized.

@johnleider johnleider self-assigned this May 18, 2020
@johnleider johnleider added this to the v3.x.x milestone May 18, 2020
@johnleider johnleider added T: feature A new feature and removed T: enhancement Functionality that enhances existing features help wanted We are looking for community help labels May 18, 2020
@johnleider johnleider changed the title [Enhancement] <v-dialog> in mobile close with the go back button [Enhancement] close VDialog when pressing the back button May 18, 2020
@JorgeMantillaHernandez

This comment has been minimized.

@barryong
Copy link

barryong commented Aug 3, 2020

Hi all, I just created a mixin to solve this problem as well. It uses Vuex to store the dialogs state and JS history.state for the back button to work. Vue Router is not require and it works in both dialog and sheet.

Here is the repo.
https://github.com/barryong/vue-dialog-mixin

It's actually just a single Vue component mixin file but I had created a package in npm for easy usage.

Feel free to comment and reach to me if you find any bugs.

@mertcanekiz

This comment has been minimized.

@JorgeMantillaHernandez

This comment has been minimized.

@jtpmbr

This comment has been minimized.

@1isten
Copy link

1isten commented Sep 1, 2020

This feature can be implemented using url hash:

<template>
  <div>
    <v-btn @click.stop="toggleDialog(true)">Open Dialog</v-btn>

    <v-dialog v-model="dialog">
      <!-- my dialog... -->
    </v-dialog>
  </div>
</template>

<script>
export default {
  data: () => ({
    dialog: false,
  }),
  watch: {
    '$route.hash'(newHash, oldHash) {
      if (newHash === '#my-dialog') {
        this.dialog = true;
      } else if (oldHash === '#my-dialog') {
        this.dialog = false;
      }
    },
  },
  methods: {
    toggleDialog(open) {
      if (open) {
        this.$router.push('#my-dialog');
      } else {
        this.$router.back(); // 😎 back button click
      }
    },
  },
};
</script>

CodePen demo

Anyway, it would be terrific if vuetify provides a built-in option to enable route hashing when toggling dialog.

@nekosaur nekosaur modified the milestones: v3.x.x, v3.0.0 Oct 13, 2020
@johnleider johnleider added this to To do in Vuetify 3 - Titan via automation Nov 30, 2020
@KaelWD KaelWD assigned KaelWD and unassigned johnleider Jun 6, 2021
@KaelWD KaelWD linked a pull request Jun 6, 2021 that will close this issue
KaelWD added a commit that referenced this issue Jun 24, 2021
@KaelWD KaelWD closed this as completed Jun 24, 2021
Vuetify 3 - Titan automation moved this from To do to Done Jun 24, 2021
@honeyamin

This comment has been minimized.

@1isten

This comment has been minimized.

@johnleider
Copy link
Member

We kindly ask users to not comment on closed/resolved issues. If you believe that this issue has not been correctly resolved, please create a new issue showing the regression or create a new discussion.

If you have any questions, please reach out to us in our Discord community.

@vuetifyjs vuetifyjs locked as resolved and limited conversation to collaborators Sep 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C: VDialog VDialog T: feature A new feature
Projects
No open projects
Development

Successfully merging a pull request may close this issue.