Skip to content

Commit 90a133f

Browse files
authored
Merge pull request #17299 from ckeditor/ck/17298
Internal (ui): Moved the document scroll lock for modal windows from `<body>` to `<html>` to make it bulletproof. Closes #17298.
2 parents c49e7b5 + bb37204 commit 90a133f

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

packages/ckeditor5-theme-lark/theme/ckeditor5-ui/components/dialog/dialog.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
}
4040
}
4141

42-
.ck-dialog-body-scroll-locked {
42+
.ck-dialog-scroll-locked {
4343
overflow: hidden;
4444
}
4545

packages/ckeditor5-ui/src/dialog/dialog.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,14 +390,14 @@ export default class Dialog extends Plugin {
390390
* Makes the <body> unscrollable (e.g. when the modal shows up).
391391
*/
392392
private _lockBodyScroll(): void {
393-
document.body.classList.add( 'ck-dialog-body-scroll-locked' );
393+
document.documentElement.classList.add( 'ck-dialog-scroll-locked' );
394394
}
395395

396396
/**
397397
* Makes the <body> scrollable again (e.g. once the modal hides).
398398
*/
399399
private _unlockBodyScroll(): void {
400-
document.body.classList.remove( 'ck-dialog-body-scroll-locked' );
400+
document.documentElement.classList.remove( 'ck-dialog-scroll-locked' );
401401
}
402402
}
403403

packages/ckeditor5-ui/tests/dialog/dialog.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,11 @@ describe( 'Dialog', () => {
266266
className: 'foo'
267267
} );
268268

269-
expect( document.body.classList.contains( 'ck-dialog-body-scroll-locked' ) ).to.be.true;
269+
expect( document.documentElement.classList.contains( 'ck-dialog-scroll-locked' ) ).to.be.true;
270270

271271
dialogPlugin.destroy();
272272

273-
expect( document.body.classList.contains( 'ck-dialog-body-scroll-locked' ) ).to.be.false;
273+
expect( document.documentElement.classList.contains( 'ck-dialog-scroll-locked' ) ).to.be.false;
274274
} );
275275
} );
276276

@@ -448,26 +448,26 @@ describe( 'Dialog', () => {
448448
} );
449449

450450
it( 'should lock document scroll if the dialog is a modal', () => {
451-
expect( document.body.classList.contains( 'ck-dialog-body-scroll-locked' ) ).to.be.false;
451+
expect( document.documentElement.classList.contains( 'ck-dialog-scroll-locked' ) ).to.be.false;
452452

453453
dialogPlugin._show( {
454454
position: DialogViewPosition.EDITOR_CENTER,
455455
isModal: true,
456456
className: 'foo'
457457
} );
458458

459-
expect( document.body.classList.contains( 'ck-dialog-body-scroll-locked' ) ).to.be.true;
459+
expect( document.documentElement.classList.contains( 'ck-dialog-scroll-locked' ) ).to.be.true;
460460
} );
461461

462462
it( 'should not lock document scroll if the dialog is not a modal', () => {
463-
expect( document.body.classList.contains( 'ck-dialog-body-scroll-locked' ) ).to.be.false;
463+
expect( document.documentElement.classList.contains( 'ck-dialog-scroll-locked' ) ).to.be.false;
464464

465465
dialogPlugin._show( {
466466
position: DialogViewPosition.EDITOR_CENTER,
467467
className: 'foo'
468468
} );
469469

470-
expect( document.body.classList.contains( 'ck-dialog-body-scroll-locked' ) ).to.be.false;
470+
expect( document.documentElement.classList.contains( 'ck-dialog-scroll-locked' ) ).to.be.false;
471471
} );
472472
} );
473473

@@ -541,19 +541,19 @@ describe( 'Dialog', () => {
541541
} );
542542

543543
it( 'should unlock document scroll if the dialog is a modal', () => {
544-
expect( document.body.classList.contains( 'ck-dialog-body-scroll-locked' ) ).to.be.false;
544+
expect( document.documentElement.classList.contains( 'ck-dialog-scroll-locked' ) ).to.be.false;
545545

546546
dialogPlugin._show( {
547547
position: DialogViewPosition.EDITOR_CENTER,
548548
isModal: true,
549549
className: 'foo'
550550
} );
551551

552-
expect( document.body.classList.contains( 'ck-dialog-body-scroll-locked' ) ).to.be.true;
552+
expect( document.documentElement.classList.contains( 'ck-dialog-scroll-locked' ) ).to.be.true;
553553

554554
dialogPlugin._hide();
555555

556-
expect( document.body.classList.contains( 'ck-dialog-body-scroll-locked' ) ).to.be.false;
556+
expect( document.documentElement.classList.contains( 'ck-dialog-scroll-locked' ) ).to.be.false;
557557
} );
558558
} );
559559
} );

0 commit comments

Comments
 (0)