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:
Tasio
2025-05-14 15:36:00 +02:00
parent 6999197243
commit 9847d4484b
3 changed files with 5 additions and 2 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+3
View File
@@ -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'));