MDL-85260 core: prevent background scrolling
After upgrading to Bootstrap 5 (Moodle v5), opening a modal no longer prevents the background content from scrolling. This fix restores the intended behavior by mimicking Bootstrap 5's JavaScript logic that disables background scrolling when a modal is open.
This commit is contained in:
Vendored
+1
-1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -898,6 +898,8 @@ export default class Modal {
|
||||
this.accessibilityShow();
|
||||
this.getModal().focus();
|
||||
$('body').addClass('modal-open');
|
||||
const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
|
||||
$('body').css({overflow: "hidden", paddingRight: `${scrollbarWidth}px`});
|
||||
this.root.trigger(ModalEvents.shown, this);
|
||||
dispatchEvent('core/modal:shown', this, this.modal[0]);
|
||||
|
||||
@@ -931,6 +933,7 @@ export default class Modal {
|
||||
// Hide the backdrop if we're the last open modal.
|
||||
backdrop.hide();
|
||||
$('body').removeClass('modal-open');
|
||||
$('body').css({overflow: "", paddingRight: ""});
|
||||
}
|
||||
|
||||
const currentIndex = parseInt(this.root.css('z-index'));
|
||||
|
||||
Reference in New Issue
Block a user