Skip to content

Commit

Permalink
Allow the modal to close when we click outside the modal content (#1897)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashkan117 committed May 2, 2024
1 parent 245dbdf commit 47e1762
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions assets/js/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ function renderModal () {
qs(MODAL_CLOSE_BUTTON_SELECTOR).addEventListener('click', event => {
closeModal()
})

qs(MODAL_SELECTOR).addEventListener('click', event => {
const classList = event.target.classList
// if we clicked on the modal overlay/parent but not the modal content
if (classList.contains('modal') && classList.contains('shown') && classList.length === 2) {
closeModal()
}
})
}

/**
Expand Down

0 comments on commit 47e1762

Please sign in to comment.