Skip to content

Commit

Permalink
Close the modal when clicking outside. #27
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Erbe committed Jul 27, 2018
1 parent 0a4250e commit 0187db2
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/plugins/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class Modal {
this.setupCloseEvent();
}

this.modalBackground = this.root.querySelector('.modal-background');
this.modalBackground.addEventListener('click', this.boundHandleCloseEvent);

/**
* Create a bound version of our event escape event handler, this will
* allow us to remove the event listener later on.
Expand Down Expand Up @@ -134,6 +137,7 @@ class Modal {
}

document.removeEventListener('keyup', this.boundHandleEscapeClose);
this.modalBackground.removeEventListener('click', this.boundHandleCloseEvent);

this.root = null;
this.closeButton = null;
Expand Down

0 comments on commit 0187db2

Please sign in to comment.