Skip to content

Commit 12b7382

Browse files
author
Helen Le
committed
Revert "fix(overlay): modal and page overlay should not allow body scroll (#5710)"
This reverts commit ee1bae6.
1 parent ba606aa commit 12b7382

File tree

2 files changed

+0
-103
lines changed

2 files changed

+0
-103
lines changed

packages/overlay/src/OverlayStack.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ class OverlayStack {
2727

2828
stack: Overlay[] = [];
2929

30-
private originalBodyOverflow = '';
31-
32-
private bodyScrollBlocked = false;
33-
3430
constructor() {
3531
this.bindEvents();
3632
}
@@ -83,25 +79,6 @@ class OverlayStack {
8379
this.stack.splice(overlayIndex, 1);
8480
}
8581
overlay.open = false;
86-
87-
this.manageBodyScroll();
88-
}
89-
90-
/**
91-
* Manage body scroll blocking based on modal/page overlays
92-
*/
93-
private manageBodyScroll(): void {
94-
const shouldBlock = this.stack.some(
95-
(overlay) => overlay.type === 'modal' || overlay.type === 'page'
96-
);
97-
if (shouldBlock && !this.bodyScrollBlocked) {
98-
this.originalBodyOverflow = document.body.style.overflow || '';
99-
document.body.style.overflow = 'hidden';
100-
this.bodyScrollBlocked = true;
101-
} else if (!shouldBlock && this.bodyScrollBlocked) {
102-
document.body.style.overflow = this.originalBodyOverflow;
103-
this.bodyScrollBlocked = false;
104-
}
10582
}
10683

10784
/**
@@ -271,7 +248,6 @@ class OverlayStack {
271248
overlay.addEventListener('beforetoggle', this.handleBeforetoggle, {
272249
once: true,
273250
});
274-
this.manageBodyScroll();
275251
});
276252
}
277253

packages/overlay/test/index.ts

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -650,85 +650,6 @@ export const runOverlayTriggerTests = (type: string): void => {
650650
'hover content is not available at point'
651651
).to.be.false;
652652
});
653-
654-
it('blocks body scroll when modal overlay is opened and restores when closed', async function () {
655-
const originalBodyOverflow = document.body.style.overflow;
656-
657-
const modalTrigger = this.outerTrigger;
658-
modalTrigger.type = 'modal';
659-
await elementUpdated(modalTrigger);
660-
661-
// Open modal overlay
662-
const opened = oneEvent(modalTrigger, 'sp-opened');
663-
this.outerButton.click();
664-
await opened;
665-
666-
// Check that body scroll is blocked
667-
expect(document.body.style.overflow).to.equal('hidden');
668-
669-
// Close modal overlay
670-
const closed = oneEvent(modalTrigger, 'sp-closed');
671-
sendMouse({
672-
steps: [
673-
{
674-
type: 'click',
675-
position: [1, 1],
676-
},
677-
],
678-
});
679-
await closed;
680-
681-
// Check that body scroll is restored
682-
expect(document.body.style.overflow).to.equal(
683-
originalBodyOverflow
684-
);
685-
});
686-
687-
it('actually prevents page scrolling when modal overlay is open and restores scrolling when closed', async function () {
688-
// Create a long enough page to enable scrolling
689-
const longContent = document.createElement('div');
690-
longContent.style.height = '200vh'; // Make page twice viewport height
691-
longContent.style.width = '100%';
692-
longContent.style.backgroundColor = 'transparent';
693-
document.body.appendChild(longContent);
694-
695-
const modalTrigger = this.outerTrigger;
696-
modalTrigger.type = 'modal';
697-
await elementUpdated(modalTrigger);
698-
699-
// Open modal overlay
700-
const opened = oneEvent(modalTrigger, 'sp-opened');
701-
this.outerButton.click();
702-
await opened;
703-
704-
// Attempt to scroll while modal is open
705-
const scrollYBeforeScroll = window.scrollY;
706-
window.scrollTo(0, 100);
707-
await nextFrame();
708-
709-
// Verify that scrolling was prevented
710-
expect(window.scrollY).to.equal(scrollYBeforeScroll);
711-
712-
// Close modal overlay
713-
const closed = oneEvent(modalTrigger, 'sp-closed');
714-
await sendMouse({
715-
steps: [
716-
{
717-
type: 'click',
718-
position: [1, 1],
719-
},
720-
],
721-
});
722-
await closed;
723-
724-
// Verify scrolling works again after modal is closed
725-
window.scrollTo(0, 100);
726-
await nextFrame();
727-
expect(window.scrollY).to.equal(100);
728-
729-
// Clean up
730-
document.body.removeChild(longContent);
731-
});
732653
});
733654
describe('System interactions', () => {
734655
afterEach(async () => {

0 commit comments

Comments
 (0)