Skip to content

Commit 7f9df7a

Browse files
tobiloebthetaPC
andauthored
fix(overlays): exclude backdrop-no-scroll class when toast is presented (#30123)
Issue number: resolves #30112 --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? When toast is presented, the `backdrop-no-scroll` class is added to the body when using Frameworks like Angular. It should not add this class as toast does not be setting focus trap as mentioned in the [comments](https://github.com/ionic-team/ionic-framework/blob/1cfa915e8fe362951c521bce970a9f5f10918ab2/core/src/utils/overlays.ts#L514-L520). ## What is the new behavior? - Class is only added when the overlay that is presented is not a toast component. - Test was added. ## Does this introduce a breaking change? - [ ] Yes - [x] No <!-- If this introduces a breaking change: 1. Describe the impact and migration path for existing applications below. 2. Update the BREAKING.md file with the breaking change. 3. Add "BREAKING CHANGE: [...]" to the commit description when merging. See https://github.com/ionic-team/ionic-framework/blob/main/docs/CONTRIBUTING.md#footer for more information. --> ## Other information N/A --------- Co-authored-by: Maria Hutt <[email protected]>
1 parent bb40a1e commit 7f9df7a

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

core/src/utils/overlays.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -520,10 +520,9 @@ export const present = async <OverlayPresentOptions>(
520520
*/
521521
if (overlay.el.tagName !== 'ION-TOAST') {
522522
setRootAriaHidden(true);
523+
document.body.classList.add(BACKDROP_NO_SCROLL);
523524
}
524525

525-
document.body.classList.add(BACKDROP_NO_SCROLL);
526-
527526
hideUnderlyingOverlaysFromScreenReaders(overlay.el);
528527
hideAnimatingOverlayFromScreenReaders(overlay.el);
529528

@@ -646,6 +645,8 @@ export const dismiss = async <OverlayDismissOptions>(
646645
return false;
647646
}
648647

648+
const presentedOverlays = doc !== undefined ? getPresentedOverlays(doc) : [];
649+
649650
/**
650651
* For accessibility, toasts lack focus traps and don’t receive
651652
* `aria-hidden` on the root element when presented.
@@ -657,7 +658,7 @@ export const dismiss = async <OverlayDismissOptions>(
657658
* Therefore, we must remove `aria-hidden` from the root element
658659
* when the last non-toast overlay is dismissed.
659660
*/
660-
const overlaysNotToast = doc !== undefined ? getPresentedOverlays(doc).filter((o) => o.tagName !== 'ION-TOAST') : [];
661+
const overlaysNotToast = presentedOverlays.filter((o) => o.tagName !== 'ION-TOAST');
661662

662663
const lastOverlayNotToast = overlaysNotToast.length === 1 && overlaysNotToast[0].id === overlay.el.id;
663664

core/src/utils/test/overlays/overlays-scroll-blocking.spec.ts

+22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { newSpecPage } from '@stencil/core/testing';
22

33
import { Modal } from '../../../components/modal/modal';
4+
import { Toast } from '../../../components/toast/toast';
45

56
describe('overlays: scroll blocking', () => {
67
it('should not block scroll when the overlay is created', async () => {
@@ -85,4 +86,25 @@ describe('overlays: scroll blocking', () => {
8586

8687
expect(body).not.toHaveClass('backdrop-no-scroll');
8788
});
89+
90+
// Fixes https://github.com/ionic-team/ionic-framework/issues/30112
91+
it('should not block scroll when the toast overlay is presented', async () => {
92+
const page = await newSpecPage({
93+
components: [Toast],
94+
html: `
95+
<ion-toast></ion-toast>
96+
`,
97+
});
98+
99+
const toast = page.body.querySelector('ion-toast')!;
100+
const body = page.doc.querySelector('body')!;
101+
102+
await toast.present();
103+
104+
expect(body).not.toHaveClass('backdrop-no-scroll');
105+
106+
await toast.dismiss();
107+
108+
expect(body).not.toHaveClass('backdrop-no-scroll');
109+
});
88110
});

0 commit comments

Comments
 (0)