Skip to content

Commit 7fd342a

Browse files
authored
Merge pull request #3489 from projectblacklight/backport-3452
backport: Let a click on backdrop behind modal close the modal
2 parents a813fdb + 03ca446 commit 7fd342a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

app/javascript/blacklight/modal.js

+6-4
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)