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

onOutsideClick get fired when body of popup get clicked (when lazy created) #13

Open
ernoaapa opened this issue Jan 20, 2016 · 2 comments
Labels

Comments

@ernoaapa
Copy link

Hi,
found an issue with the onOutsideClick handler. It get fired even if I click input field inside the popup.
(Note that this is not duplicate with previous reported issue)

If I render SweetAlert but don't show it yet and later on change the show:true, then this invalid behavior happens. If I have show:true on initial render time, then everything works.

Looks like that if it's show:false, when registerOutsideClickHandler get executed, it document.getElementsByClassName('sweet-alert') returns null (of course because the popup is not created.

Found out that if I move the registerOutsideClickHandler from componentDidMount after the place in setupWithProps where it creates the popup then it starts to work.

@rkcreation
Copy link

+1

@chentsulin
Copy link
Owner

Sorry for late reply. I think we can avoid handler be executed when targetNode is null or undefined.

export default function outsideTargetHandlerFactory(targetNode, eventHandler) {
  return (evt) => {
    evt.stopPropagation();
    if (!targetNode) return; // <------- Added this line should fix this
    let current = evt.target;
    let found = false;
    while (current.parentNode) {
      found = isDOMEquals(current, targetNode);
      if (found) return;
      current = current.parentNode;
    }
    eventHandler(evt);
  };
}

@chentsulin chentsulin added the bug label Nov 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants