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

Click off of material dialog to close #4

Open
1j01 opened this issue Jan 18, 2018 · 0 comments
Open

Click off of material dialog to close #4

1j01 opened this issue Jan 18, 2018 · 0 comments

Comments

@1j01
Copy link
Owner

1j01 commented Jan 18, 2018

I want this to work personally and it's also part of the spec, but the library I'm using doesn't support it:
google/material-design-lite#5030

There's a workaround solution proposed here: google/material-design-lite#5030

document.querySelector('.dialog-show').addEventListener('click', function() {
  document.querySelector('dialog').showModal();
  document.querySelector('dialog').addEventListener('click', outsideDialog);
});


function outsideDialog(event) {
  var dialog = this;
  var rect = dialog.getBoundingClientRect();
  var isInDialog = (
    rect.top <= event.clientY && event.clientY <= rect.top + rect.height &&
    rect.left <= event.clientX && event.clientX <= rect.left + rect.width
  );
  if (!isInDialog) {
    dialog.close();
    dialog.removeEventListener('click', outsideDialog);
  }
}
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

1 participant