Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions core/src/components/modal/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,10 @@ export class Modal implements ComponentInterface, OverlayInterface {
await waitForMount();
}

// Recalculate content dimensions before showing the modal so the initial
// paint uses the final content offset and background geometry.
await this.recalculateContentDimensions();

writeTask(() => this.el.classList.add('show-modal'));

// Recalculate isSheetModal before safe-area setup because framework
Expand Down Expand Up @@ -1517,6 +1521,18 @@ export class Modal implements ComponentInterface, OverlayInterface {
this.applyFullscreenSafeAreaTo(contentEl, hasFooter);
}

/**
* Recalculates the inner ion-content dimensions after the modal has mounted so
* its offsets and background geometry reflect the modal's final size before it is shown.
*/
private async recalculateContentDimensions(): Promise<void> {
const contentEl = this.el.querySelector('ion-content') as HTMLIonContentElement | null;

if (contentEl) {
await contentEl.recalculateDimensions();
}
}

/**
* Sets --internal-content-safe-area-padding-bottom on the given ion-content
* when no footer is present, so ion-content's .inner-scroll includes
Expand Down
23 changes: 23 additions & 0 deletions core/src/components/modal/test/basic/modal.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { h } from '@stencil/core';
import { newSpecPage } from '@stencil/core/testing';

import { Modal } from '../../modal';
import { Content } from '../../../content/content';
import { FOCUS_TRAP_DISABLE_CLASS } from '@utils/overlays';

describe('modal: htmlAttributes inheritance', () => {
Expand Down Expand Up @@ -39,3 +40,25 @@ describe('modal: focus trap', () => {
expect(modal.classList.contains(FOCUS_TRAP_DISABLE_CLASS)).toBe(false);
});
});

describe('modal: content dimensions', () => {
it('should recalculate ion-content dimensions before presenting', async () => {
const page = await newSpecPage({
components: [Content, Modal],
template: () => (
<ion-modal overlayIndex={1} animated={false}>
<ion-content color="dark">Test Content</ion-content>
</ion-modal>
),
});

const modal = page.body.querySelector('ion-modal')!;

const recalculateSpy = jest.spyOn(Content.prototype, 'recalculateDimensions').mockResolvedValue(undefined);

await modal.present();
await page.waitForChanges();

expect(recalculateSpy).toHaveBeenCalledTimes(1);
});
});