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

modal can't open again when modal closed twice #291

Open
forjuan opened this issue Dec 14, 2017 · 2 comments
Open

modal can't open again when modal closed twice #291

forjuan opened this issue Dec 14, 2017 · 2 comments

Comments

@forjuan
Copy link

forjuan commented Dec 14, 2017

I should not close modal twice, but I really did. Then I found I can't open remodal again. Finally I found animationend event can't be triggered when wrapper element's value of display attribute is none, so the wrapper state will be closing and never change back. maybe can set hidden to the value of wrapper's visibility attribute to solve this problem.

` Remodal.prototype.close = function(reason) {
var remodal = this;

  // Check if the animation was completed
if (remodal.state === STATES.OPENING || remodal.state === STATES.CLOSING || remodal.state === STATES.CLOSED) {
  return;
}

if (
  remodal.settings.hashTracking &&
  remodal.$modal.attr('data-' + PLUGIN_NAME + '-id') === location.hash.substr(1)
) {
  location.hash = '';
  $(window).scrollTop(scrollTop);
}

syncWithAnimation(
  function() {
    setState(remodal, STATES.CLOSING, false, reason);
  },

  function() {
    remodal.$bg.removeClass(remodal.settings.modifier);
    remodal.$overlay.removeClass(remodal.settings.modifier).hide();
   //====================here=================
   //remodal wraper hide()(display: none) when remodal first closed 
   // but it will never finish the css animation when element's value of display is none, it never trigger animationend event, the state will always be closing, so it won't work when we open the remodal next time
    remodal.$wrapper.hide();
    unlockScreen();

    setState(remodal, STATES.CLOSED, false, reason);
  },

  remodal);

};`

@sukima
Copy link

sukima commented Apr 20, 2018

This is a very frustrating bug! It means that modal.close() is unsafe! Now we have to guard against it?! Especially since the modal can close itself which means if you code calls close from an action hook your screwed!

@sukima
Copy link

sukima commented Feb 5, 2019

I use a work around to handle this use case. It uses a Confirmer object to handle the complexity as follows:

function openModal() {
  return new Confirmer(resolver => {
    let inst = $('[data-remodal-id=modal]').remodal();
    let promise = inst.open();
    resolver.dispose(() => {
      return promise.then(() => {
        let modalState = inst.getState();
        // https://github.com/vodkabears/Remodal/issues/291
        if (modalState !== 'opened') { return; }
        return inst.close();
      });
    });
  });
}

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