I have a modal which should have height based on its content, since content could differ from modal to modal. Modal is shown from bottom of the page and is not full screen.
How can I achieve modal behaviour where modals height is equal to its content. Currently whenever modal is opened I calculate height of modals content and then set modals height to it, but this is very bad IMO since it does this on every modal open. If i set height to something like auto or content-fit it is not shown. There must be easier way to do this.
Thanks for reply, but you set height to fixed 20%, i need it to change as content inside modal change. But what might help is that i was targeting modal class and not modal wrappet, i will try my css on modal wrapper and let you know how it went.
Correct. That is why I said “if css can do it”. The code sample is to show the css selector you need to target the right element in the DOM. This is generally the issue with modal.
if there is CSS code that can do what you want, put it in your scss (global.scss?) to target the element as shown earlier. And make sure the modal is opened with the designated class attached to it - using the properties needed to open a modal.
So:
.my-custom-modal-css .modal-wrapper {
.... HERE YOUR MAGICAL CSS
}
Ahh sorry. I tried it with targeting .modal-wrapper. No success, when setting its height to auto modal just disappears. I do not know any other way to do this.
Edit: I found dozens of answers online but none of them seem to work ,at least for Ionic 5.
If @twestrick 's great code suggestion does not work, maybe use the inspector to inspect the class of the modal elements. But I think the CSS selectors he is showing are way better than mine
I have created component like yours(PopupMessage) called Modal.
This is the structure(simplified)
<Modal>
everything as you put in your PopupMessage
<slot>
</Modal>
Then in a page i call this and send content of modal as a slot. This content has another component inside it but it is not rendered as the 1st one, 1st one is rendered as and the 2nd one is just , like it doesnt recognize it is an modal. Dont know why.
Edit2: i just edited your css to target .auto-height and not ion-modal.auto-height and it works now.
Thank you so much, I initially saw the code you used as reference but i didnt know what to do with it.
To be honest I actually do not know how this works.