Skip to content

fix(modal): prevent ion-content collapsing at content-based heights - #31413

Open
brandyscarney wants to merge 8 commits into
mainfrom
FW-7731
Open

fix(modal): prevent ion-content collapsing at content-based heights#31413
brandyscarney wants to merge 8 commits into
mainfrom
FW-7731

Conversation

@brandyscarney

@brandyscarney brandyscarney commented Aug 28, 2026

Copy link
Copy Markdown
Member

Issue number: resolves #31149


What is the current behavior?

Setting --height to any of the following on an ion-modal containing an ion-content results in the ion-content collapsing to 0 height: auto, fit-content, min-content, or max-content.

What is the new behavior?

  • Checks if modal --height is set to auto, fit-content, min-content, or max-content and styles the ion-content, ion-nav and .ion-page appropriately if so
  • Watches for changes to --height on ion-modal to dynamically add and remove the class that sizes the ion-content to its content
  • Updates modal --max-height to 100% which allows the content to scroll instead of overflowing and being clipped
  • Adds a preview test for different scenarios where ion-modal has --height set
  • Adds e2e tests for the various --height scenarios

Does this introduce a breaking change?

  • Yes
  • No

Other information

Dev build: 9.0.1-dev.11788212611.154b1596

Preview: Modal: Content Height

Docs PR: ionic-team/ionic-docs#4689

@vercel

vercel Bot commented Aug 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ionic-framework Ready Ready Preview Sep 2, 2026 9:21pm UTC

Request Review

Comment thread core/src/components/content/content.tsx Outdated
}

const height = getComputedStyle(modal).getPropertyValue('--height').trim();
return CONTENT_SIZED_HEIGHTS.includes(height);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this PR is still a work in progress! 🙂

@thetaPC thetaPC left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly waiting on the breaking change question to be resolved.

Comment thread core/src/components/content/content.tsx Outdated
* Compared as a suffix so a value carrying only a vendor prefix is still
* recognized, such as the `-moz-fit-content` that Firefox needs before 94.
*
* TODO: replace with `CONTENT_SIZED_HEIGHTS.includes(height)` once the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we create a ticket to associate this todo?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not even sure we need to do this really. It doesn't hurt to keep this in indefinitely, and I'm not sure what the goal of the ticket would be. Dropping Firefox support for what reason?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewrote so it is no longer a TODO: 7298645

Comment thread core/src/components/modal/test/content-height/modal.e2e.ts
* overlay, giving the wrapper's flex children something to shrink
* toward so `ion-content` scrolls instead of overflowing.
*/
--max-height: 100%;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this considered a breaking change since consumers are used to having it as auto?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I wouldn't consider this a breaking change because auto was never a valid value for max-height in the first place.

auto isn't listed as a valid value in the docs for max-height. As a result, max-height: auto is invalid and the property fell back to its initial value, none. If you inspect any .modal-wrapper prior to this change you will see the max-height is computed as none:

CleanShot 2026-09-02 at 16 57 53

That means the actual change is none100%.

From there, the cases where the computed value actually changes are all cases that were already broken:

  • --height: 100% (the default) and every built-in variant (calc(100% - 40px), sheet, card, inset heights) are all ≤ 100%, so the clamp has no effect and rendering remains identical.
  • The iOS card modal sets --max-height: 1000px explicitly, so it's unaffected.
  • A --height taller than the overlay (e.g. 800px in a 600px viewport, or a content-based height with tall content) previously overflowed the host. Since :host has contain: strict, that overflow was clipped at both the top and bottom, leaving some of the content unreachable. Clamping the height so ion-content scrolls instead is a fix.

Anyone who explicitly sets --max-height: auto still ends up with none, since their override is just as invalid as the old default was. And setting --max-height to anything else will still take precedence.

Additionally, CSS variable defaults are not tracked in the public API. api.txt records CSS custom property names only, so there are no generated docs or API diff changes.

* for that and re-evaluate. Viewport driven changes are already covered by
* the `resize` listener.
*/
private setupSizeToContentObserver() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I missed it, we should also add the limitation note in this file just in case we forget about it since it's only in docs.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you're talking about the limitation of setting --height on ion-modal and it not looking for height on nested elements. Let me know if I am misunderstanding: 6738339

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: core @ionic/core package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: ion-modal doesn't show content with auto height

2 participants