Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

feat(modal): prevent location change if modal is open #1334

Closed
wants to merge 3 commits into from
Closed

feat(modal): prevent location change if modal is open #1334

wants to merge 3 commits into from

Conversation

ubenzer
Copy link

@ubenzer ubenzer commented Dec 2, 2013

You are in a state that modal is open. User accidentally clicks back
button on the browser. You use a state manager, for example ui-router,
so page transition happens, without page refresh. Now, you have a
completely different page, completely different state, but you have
modal open.

This PR prevents URL change if modal is open.

You are in a state that modal is open. User accidentally clicks back
button on the browser. You use a state manager, for example ui-router,
so page transition happens, without page refresh. Now, you have a
completely different page, completely different state, but you have
modal open.

This PR prevents URL change if modal is open.
@pkozlowski-opensource
Copy link
Member

@ubenzer this is one possible approach. Alternatively we could simply dismiss all the modals on the location change. I really can't decide which one is better.

In any case this change will need a passing unit test before it can be merged.

@ubenzer
Copy link
Author

ubenzer commented Dec 4, 2013

I am not good at JavaScript unit testing and I have no idea about how to simulate browser url change. I thought about including ngRouter or uiRouter to testing environment but this is not something that makes sense for unit testing I guess... I am kinda confused.

I'll look to uiRouter's tests once I have time, hoping there might be some samples that help me.

@pkozlowski-opensource
Copy link
Member

@ubenzer you don't need ui-rooter to write a test, you just need to simulate a page change by triggering the locationStart event.

But once again, my main problem here is the conceptual one - should we do what you are proposing or rather close modals on location change...

@ubenzer
Copy link
Author

ubenzer commented Dec 4, 2013

@pkozlowski-opensource I understand, and agree with your problem. It is probably better to close modals on location change. I'll implement that too and see it in action in our app, a real app with real problems to see it fits better.

I'll do that and update my PR when I have some time.

P.S. I've never though about triggering event manually, thanks for the tip. :)

You are in a state that modal is open. User clicks back
button on the browser. You use a state manager, for example ui-router,
so page transition happens, without page refresh. Now, you have a
completely different page, completely different state, but you have
modal open.

To prevent this situation, modals are closed automatically on
`$locationChangeStart` Developer may prevent this behaviour by passing
`closeOnNavigation: false` as option.
@ubenzer
Copy link
Author

ubenzer commented Dec 10, 2013

@pkozlowski-opensource I've updated the PR. It closes modal, but people are able to prevent it by closeOnNavigation: false is they wish now.

@pkozlowski-opensource
Copy link
Member

@ubenzer sorry, it took me a bit of time to come back to you regarding this one, but finally I've found some time to review your latest change and left some comments in the code. WDYT?

Also, could you please rebase your branch on the latest master and squash all the commits into one? Thnx!

@ubenzer
Copy link
Author

ubenzer commented Dec 25, 2013

@pkozlowski-opensource Your concerns are right, I'll update my PR when I find time. Thanks for feedbacks, happy new year. :)

@pkozlowski-opensource
Copy link
Member

@ubenzer haven't heard from you so started to move on the topic in #1552

@farolfo
Copy link

farolfo commented Jul 15, 2014

Has this been removed from the project? I cannot find this pull request merged in the project. May be I'm missing something haha

@wlingke
Copy link

wlingke commented Jul 21, 2014

Yea what happened to this feature? This doesn't work for me either with latest version.

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

Successfully merging this pull request may close these issues.

4 participants