Skip to content

Commit 6b1d698

Browse files
authored
Merge pull request #3452 from projectblacklight/click_in_modal_backdrop_closes
Let a click on backdrop behind modal close the modal
2 parents 391979b + f9b47b1 commit 6b1d698

File tree

1 file changed

+6
-4
lines changed
  • app/javascript/blacklight-frontend

1 file changed

+6
-4
lines changed

app/javascript/blacklight-frontend/modal.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,15 @@ const Modal = (() => {
148148
};
149149

150150
modal.setupModal = function() {
151-
// Register both trigger and preserve selectors in ONE event handler, combining
152-
// into one selector with a comma, so if something matches BOTH selectors, it
153-
// still only gets the event handler called once.
151+
// Register several click handlers in ONE event handler for efficiency
152+
//
153+
// * close button OR click on backdrop (modal.modalSelector) closes modal
154+
// * trigger and preserve link in modal functionality -- if somethign matches both trigger and
155+
// preserve, still only called once.
154156
document.addEventListener('click', (e) => {
155157
if (e.target.closest(`${modal.triggerLinkSelector}, ${modal.preserveLinkSelector}`))
156158
modal.modalAjaxLinkClick(e)
157-
else if (e.target.closest('[data-bl-dismiss="modal"]'))
159+
else if (e.target.matches(`${modal.modalSelector}`) || e.target.closest('[data-bl-dismiss="modal"]'))
158160
modal.hide()
159161
})
160162
};

0 commit comments

Comments
 (0)