From 4634387295d1e294086c22a512c7d98b8b68eeda Mon Sep 17 00:00:00 2001 From: shkomg Date: Mon, 2 Nov 2026 20:17:20 +0100 Subject: [PATCH] fix(modal): allow backdrop-filter inside md modal The md enter animation stayed applied to `.modal-wrapper` after it finished, because it used the default `both` fill and the overlay keeps the animation until dismiss. An element with an applied opacity animation is a backdrop root in Chromium, so `backdrop-filter` on content inside the modal could only see the modal itself and blurred nothing. The wrapper animation now uses a `backwards` fill and sets its end state (opacity 1, no offset) as inline styles when it finishes, so the modal looks the same but the finished animation is no longer applied. --- .../components/modal/animations/md.enter.ts | 17 ++++++--- .../modal/test/animations/modal.e2e.ts | 36 +++++++++++++++++++ 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/core/src/components/modal/animations/md.enter.ts b/core/src/components/modal/animations/md.enter.ts index 97dc0a4b200..7327186472b 100644 --- a/core/src/components/modal/animations/md.enter.ts +++ b/core/src/components/modal/animations/md.enter.ts @@ -14,10 +14,19 @@ const createEnterAnimation = () => { }) .afterClearStyles(['pointer-events']); - const wrapperAnimation = createAnimation().keyframes([ - { offset: 0, opacity: 0.01, transform: 'translateY(40px)' }, - { offset: 1, opacity: 1, transform: `translateY(0px)` }, - ]); + /** + * The finished animation must not stay applied to the wrapper. + * An element with an applied opacity animation is a backdrop root, + * so `backdrop-filter` inside the modal could not see the page + * behind it. The end state is set as inline styles instead. + */ + const wrapperAnimation = createAnimation() + .fill('backwards') + .afterStyles({ opacity: '1', transform: 'translateY(0px)' }) + .keyframes([ + { offset: 0, opacity: 0.01, transform: 'translateY(40px)' }, + { offset: 1, opacity: 1, transform: `translateY(0px)` }, + ]); return { backdropAnimation, wrapperAnimation, contentAnimation: undefined }; }; diff --git a/core/src/components/modal/test/animations/modal.e2e.ts b/core/src/components/modal/test/animations/modal.e2e.ts index 8d541003ff8..545af321713 100644 --- a/core/src/components/modal/test/animations/modal.e2e.ts +++ b/core/src/components/modal/test/animations/modal.e2e.ts @@ -43,3 +43,39 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ config, title }) => }); }); }); + +configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ config, title }) => { + test.describe(title('modal: animations'), () => { + test('should not keep the enter animation applied to the wrapper', async ({ page }, testInfo) => { + testInfo.annotations.push({ + type: 'issue', + description: 'https://github.com/ionic-team/ionic-framework/issues/31603', + }); + + await page.setContent( + ` + + `, + config + ); + + const ionModalDidPresent = await page.spyOnEvent('ionModalDidPresent'); + const modal = page.locator('ion-modal'); + + await modal.evaluate((el: HTMLIonModalElement) => el.present()); + await ionModalDidPresent.next(); + + const wrapper = page.locator('ion-modal .modal-wrapper'); + + /** + * An applied opacity animation makes the wrapper a backdrop root, + * which breaks `backdrop-filter` on content inside the modal. + */ + const wrapperAnimations = await wrapper.evaluate((el: HTMLElement) => el.getAnimations().length); + expect(wrapperAnimations).toBe(0); + + await expect(wrapper).toHaveCSS('opacity', '1'); + await expect(wrapper).toHaveCSS('transform', 'matrix(1, 0, 0, 1, 0, 0)'); + }); + }); +});