Skip to content

Click off of material dialog to close #4

Description

@1j01

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);
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions