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)'); + }); + }); +});