-
Notifications
You must be signed in to change notification settings - Fork 13.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: setting ion-modal width or height CSS properties to auto results in size of 0 #24080
Comments
Thanks for the issue. I can reproduce this behavior, but I need to spend more time digging into the source of the issue. I will follow up here when I have more to share. |
Hi, I've dug into this and confirmed that the It looks like the cause is that both the outer In the meantime, another possible workaround would be to set |
In march of 2019 sonichk provided a fix for this in https://forum.ionicframework.com/t/dynamic-modal-height-based-on-content-in-ionic-v4/139595/9 but then you would have to replace the ion-content in your modal with a
|
Since Ionic v6, you can no longer target the direct So you can no longer do: /* global.scss */
ion-modal {
--width: auto;
--height: auto;
--max-width: 90%;
--max-height: 90%;
--overflow: auto;
.modal-wrapper > .ion-page {
position: static;
contain: initial;
}
} But thanks to the shadow DOM, the injected component is now seen as the direct child of the modal, which allow us to target it directly without using the wrapper. Here is what I came up with: /* global.scss */
ion-modal {
--width: auto;
--height: auto;
--max-width: 90%;
--max-height: 90%;
--overflow: auto;
> .ion-page {
position: static;
contain: initial;
}
} You can put whatever max width & max height you want, but you have to set them in order for the modal to be scrollable instead of it overflowing the size of your device's screen if you have to much content inside of it. I recommend only targeting the direct As for the And finally for the |
This is still an issue. The three options of a modal are "to different" from what a modal was originally, so we also modified the style of it. (basically a floating card) using
No problems while testing on the browser, devices won't show the modal nevertheless. |
Hi everyone, I have a PR up that should improve our compatibility with custom dialogs: #25630 Here is a dev build if anyone is interested in testing: A few notes about this change:
Here is an example CodePen: https://codepen.io/liamdebeasi/pen/BarLXee |
I can confirm that it fixes the issue 🚀 |
Thanks for the issue. This has been resolved via #25630, and a fix will be available in an upcoming release of Ionic Framework. |
When this ships we will also publish new documentation here: https://ionicframework.com/docs/api/modal |
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out. |
Prerequisites
Ionic Framework Version
Current Behavior
According to Ionic documentations, when creating an alert with complex form, we should use a modal instead
I'm trying to create a simple alert which prompt the user to confirm his password before validating critical actions, but I can't add form validations on a
<ion-alert>
, so I switched to a<ion-modal>
on which I try to replicate the design of an<ion-alert>
using CSS properties (--width, --height, ...) so the modal doesn't take the entire app's viewport but appears floating on top of the current page, but setting them completely break the modal, which I don't think is expectedExpected Behavior
Using the CSS properties defined by Ionic: --width, --height, --min-width, --min-height, --max-width & --max-height, I should be able to create a floating modal on top of the current content
If the
<ion-modal>
isn't expected to be used to create floating modal, then all these CSS properties as well as --backdrop-opacity, --border-radius & --box-shadow are uselessSteps to Reproduce
Inside the component which create the modal:
Inside the global.scss file:
Code Reproduction URL
No response
Ionic Info
@ionic/angular: 5.8.4
@ionic/cli: 6.17.1
@angular/cli: 12.2.10
@capacitor/cli: 3.2.5
NodeJS: 16.11.1
npm: 8.0.0
Additional Information
Here is a video demonstrating the issue on Firefox & Chrome and what the problem is:
https://youtu.be/JvJQbTfKsrw
As you can see I'm able to fix the issue doing some manipulations on the Component inside the
.ion-wrapper
:On Firefox, adding these CSS rules
display: block;
&position: static;
is enought to fix the problem, but on Chrome I also have to add the rulecontain: initial;
A quicker fix would be to be able to remove the
ion-page
class that is automagically added to my Component, as all the 3 CSS rules I added are here to override the ones defined by.ion-page
I opened this as a bug as the
ion-page
class makes it impossible to resize the modal using the CSS properties defined by the<ion-modal>
without overriding the.ion-page
CSS rules, but it can also be seen as a feature request, by adding an option to control whether or not we want theion-page
class to be automagically added to our component, for example, when creating the modal:The text was updated successfully, but these errors were encountered: