Skip to content

Commit fad722e

Browse files
authored
Merge pull request #3531 from projectblacklight/bl8-backport-3447-3453-modal-scroll
[8.x] Backport two facet modal scrolling bugfixes
2 parents 119e276 + 57f632a commit fad722e

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

app/assets/stylesheets/blacklight/_bootstrap_overrides.scss

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,16 @@
2727
white-space: nowrap;
2828
}
2929

30-
.modal[open] {
30+
// Blacklight's decision to try to use bootstrap modal CSS with an html5 dialog --
31+
// in such a way the <dialog> element actually serves as the modal backdrop --
32+
// requires some fixes to both bootstrap CSS and user-agent default css
33+
dialog.modal[open] {
3134
// override bootstrap .modal class default display: none
3235
// since we aren't using bootstrap JS that sets and unsets the display
3336
display: block;
3437
background: none;
3538
border: none;
39+
40+
max-height: unset; // override user-agent dialog
41+
max-width: unset; // override user-agent dialog
3642
}

app/javascript/blacklight/modal.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656
const Modal = (() => {
5757
const modal = {}
5858

59+
// bootstrap class that will stop body scrolling when modal is open
60+
const bootstrapBodyClassOpen = "modal-open";
61+
5962
// a Bootstrap modal div that should be already on the page hidden
6063
modal.modalSelector = '#blacklight-modal';
6164

@@ -170,6 +173,12 @@ const Modal = (() => {
170173
dom.dispatchEvent(e)
171174

172175
dom.close()
176+
177+
// Turn body scrolling back to what it was
178+
document.body.style["overflow"] = modal.originalBodyOverflow;
179+
document.body.style["padding-right"] = modal.originalBodyPaddingRight;
180+
modal.originalBodyOverflow = undefined;
181+
modal.originalBodyPaddingRight = undefined;
173182
}
174183

175184
modal.show = function(el) {
@@ -181,6 +190,12 @@ const Modal = (() => {
181190
dom.dispatchEvent(e)
182191

183192
dom.showModal()
193+
194+
// Turn off body scrolling
195+
modal.originalBodyOverflow = document.body.style['overflow'];
196+
modal.originalBodyPaddingRight = document.body.style['padding-right'];
197+
document.body.style["overflow"] = "hidden"
198+
document.body.style["padding-right"] = "0px"
184199
}
185200

186201
modal.target = function() {

0 commit comments

Comments
 (0)