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()', () => {