From 63a06a87b78f9757e4b219651da348b2edda2c24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Jarz=C4=99bski?= Date: Thu, 19 Dec 2024 12:09:45 +0100 Subject: [PATCH] Add a condition for reenabling the page scroll. --- packages/ckeditor5-ui/src/dialog/dialog.ts | 4 +++- packages/ckeditor5-ui/tests/dialog/dialog.js | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/ckeditor5-ui/src/dialog/dialog.ts b/packages/ckeditor5-ui/src/dialog/dialog.ts index 27a00149f17..fe082dff12a 100644 --- a/packages/ckeditor5-ui/src/dialog/dialog.ts +++ b/packages/ckeditor5-ui/src/dialog/dialog.ts @@ -100,7 +100,9 @@ export default class Dialog extends Plugin { public override destroy(): void { super.destroy(); - this._unlockBodyScroll(); + if ( Dialog._visibleDialogPlugin === this ) { + this._unlockBodyScroll(); + } } /** diff --git a/packages/ckeditor5-ui/tests/dialog/dialog.js b/packages/ckeditor5-ui/tests/dialog/dialog.js index 171dd03526a..6072356bd12 100644 --- a/packages/ckeditor5-ui/tests/dialog/dialog.js +++ b/packages/ckeditor5-ui/tests/dialog/dialog.js @@ -272,6 +272,24 @@ describe( 'Dialog', () => { expect( document.documentElement.classList.contains( 'ck-dialog-scroll-locked' ) ).to.be.false; } ); + + it( 'should not unlock scrolling on the document if modal was displayed by another plugin instance', () => { + const tempDialogPlugin = new Dialog( editor ); + + tempDialogPlugin._show( { + position: DialogViewPosition.EDITOR_CENTER, + isModal: true, + className: 'foo' + } ); + + expect( document.documentElement.classList.contains( 'ck-dialog-scroll-locked' ) ).to.be.true; + + dialogPlugin.destroy(); + + expect( document.documentElement.classList.contains( 'ck-dialog-scroll-locked' ) ).to.be.true; + + tempDialogPlugin.destroy(); + } ); } ); describe( 'show()', () => {