-
Notifications
You must be signed in to change notification settings - Fork 3.2k
docs(modal): reorganize Styling and add Sizing to Content section #4689
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
base: main
Are you sure you want to change the base?
Changes from all commits
f73878a
80cb755
29fb8b8
9856417
db5de70
8af8824
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -127,7 +127,7 @@ import CardExample from '@site/static/usage/v9/modal/card/basic/index.mdx'; | |
|
|
||
| :::info | ||
|
|
||
| [Content](./content) should be used inside of the sheet modal if you want your modal content to be scrollable. | ||
| [Content](./content.mdx) should be used inside of the sheet modal if you want your modal content to be scrollable. | ||
|
|
||
| ::: | ||
|
|
||
|
|
@@ -175,34 +175,58 @@ import SheetScrollingContentExample from '@site/static/usage/v9/modal/sheet/expa | |
|
|
||
| <SheetScrollingContentExample /> | ||
|
|
||
| ## Styling | ||
| ## Theming | ||
|
|
||
| Modals are presented at the root of your application so they overlay your entire app. This behavior applies to both inline modals and modals presented from a controller. As a result, custom modal styles can not be scoped to a particular component as they will not apply to the modal. Instead, styles must be applied globally. For most developers, placing the custom styles in `global.css` is sufficient. | ||
| [Controller modals](#controller-modals) are appended to the root of your application, outside of the component that presented them. Component-scoped styles will not reach these modals, so their styles must be applied globally, from a stylesheet that is not scoped to a component. | ||
|
|
||
| :::note | ||
| [Inline modals](#inline-modals-recommended) stay where they are declared in your template, so component-scoped styles do apply to them. | ||
|
Comment on lines
+180
to
+182
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can revert this if desired - but I don't know why inline modals were specified here as needing to be overridden globally. We can target |
||
|
|
||
| If you are building an Ionic Angular app, the styles need to be added to a global stylesheet file. Read [Style Placement](#style-placement) in the Angular section below for more information. | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Style Placement section has been removed since v6 so I deleted this entire note: 997fe9e |
||
| ### Styling | ||
|
|
||
| ::: | ||
| Modals expose [CSS Custom Properties](#css-custom-properties) and [CSS Shadow Parts](#css-shadow-parts) for customizing their appearance. | ||
|
|
||
| :::note | ||
| import ThemeExample from '@site/static/usage/v9/modal/styling/theming/index.mdx'; | ||
|
|
||
| `ion-modal` works under the assumption that stacked modals are the same size. As a result, each subsequent modal will have no box shadow and a backdrop opacity of `0`. This is to avoid the effect of shadows and backdrops getting darker with each added modal. This can be changed by setting the `--box-shadow` and `--backdrop-opacity` CSS variables: | ||
| <ThemeExample /> | ||
|
|
||
| ::: | ||
| ### Stacked Modals | ||
|
|
||
| ``` | ||
| `ion-modal` works under the assumption that stacked modals are the same size. As a result, each subsequent modal will have no box shadow and a backdrop opacity of `0`. This is to avoid the effect of shadows and backdrops getting darker with each added modal. This can be changed by setting the `--box-shadow` and `--backdrop-opacity` CSS variables: | ||
|
|
||
| ```css | ||
| ion-modal.stack-modal { | ||
| --box-shadow: 0 28px 48px rgba(0, 0, 0, 0.4); | ||
| --backdrop-opacity: var(--ion-backdrop-opacity, 0.32); | ||
| } | ||
| ``` | ||
|
|
||
| import ThemeExample from '@site/static/usage/v9/modal/styling/theming/index.mdx'; | ||
| ### Sizing to Content | ||
|
|
||
| <ThemeExample /> | ||
| A modal fills the height of its container by default. Setting the `--height` CSS variable to `auto`, `fit-content`, `min-content`, or `max-content` sizes the modal to the height of what it renders instead. | ||
|
|
||
| :::warning | ||
|
|
||
| The height must be set on the modal through the `--height` CSS variable. Setting `height` on the `content` [CSS Shadow Part](#css-shadow-parts) will still resize the modal, but any [Content](./content.mdx) inside of it will collapse to a height of `0`, leaving only the header visible. | ||
|
|
||
| ```css | ||
| /* DO NOT DO THIS */ | ||
| ion-modal::part(content) { | ||
| height: fit-content; | ||
| } | ||
|
|
||
| /* Do this instead */ | ||
| ion-modal { | ||
| --height: fit-content; | ||
| } | ||
| ``` | ||
|
|
||
| ::: | ||
|
|
||
| import SizingToContentExample from '@site/static/usage/v9/modal/styling/sizing-to-content/index.mdx'; | ||
|
|
||
| <SizingToContentExample /> | ||
|
|
||
| ### Animations | ||
| ## Animations | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I promoted Animations out of Theming because it doesn't actually change any styles. |
||
|
|
||
| The enter and leave animations can be customized by using our animation builder and assigning animations to `enterAnimation` and `leaveAnimation`. | ||
|
|
||
|
|
@@ -220,7 +244,7 @@ import CustomDialogs from '@site/static/usage/v9/modal/custom-dialogs/index.mdx' | |
|
|
||
| A few things to keep in mind when creating custom dialogs: | ||
|
|
||
| - `ion-content` is intended to be used in full-page modals, cards, and sheets. If your custom dialog has a dynamic or unknown size, `ion-content` should not be used. | ||
| - `ion-content` can be used in a custom dialog, including one that is sized to its contents. The dialog's height must come from the `--height` CSS variable rather than from the dialog's children. See [Sizing to Content](#sizing-to-content). | ||
| - Creating custom dialogs provides a way of ejecting from the default modal experience. As a result, custom dialogs should not be used with card or sheet modals. | ||
|
|
||
| ## Event Handling | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| ```css | ||
| ion-modal { | ||
| --height: fit-content; | ||
| --width: 90%; | ||
| --border-radius: 8px; | ||
| --box-shadow: 0 28px 48px rgba(0, 0, 0, 0.4); | ||
| } | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| ```html | ||
| <ion-header> | ||
| <ion-toolbar> | ||
| <ion-title>App</ion-title> | ||
| </ion-toolbar> | ||
| </ion-header> | ||
| <ion-content class="ion-padding"> | ||
| <ion-button id="open-modal" expand="block">Open Modal</ion-button> | ||
|
|
||
| <ion-modal #modal trigger="open-modal"> | ||
| <ng-template> | ||
| <ion-header> | ||
| <ion-toolbar> | ||
| <ion-title>Modal</ion-title> | ||
| <ion-buttons slot="end"> | ||
| <ion-button (click)="modal.dismiss()">Close</ion-button> | ||
| </ion-buttons> | ||
| </ion-toolbar> | ||
| </ion-header> | ||
| <ion-content> | ||
| <ion-list lines="full"> | ||
| @for (item of ['Item 1', 'Item 2', 'Item 3']; track item) { | ||
| <ion-item> | ||
| <ion-label>{{ item }}</ion-label> | ||
| </ion-item> | ||
| } | ||
| </ion-list> | ||
| </ion-content> | ||
| </ng-template> | ||
| </ion-modal> | ||
| </ion-content> | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| ```ts | ||
| import { Component } from '@angular/core'; | ||
| import { | ||
| IonButton, | ||
| IonButtons, | ||
| IonContent, | ||
| IonHeader, | ||
| IonItem, | ||
| IonLabel, | ||
| IonList, | ||
| IonModal, | ||
| IonTitle, | ||
| IonToolbar, | ||
| } from '@ionic/angular'; | ||
|
|
||
| @Component({ | ||
| selector: 'app-example', | ||
| templateUrl: 'example.component.html', | ||
| styleUrls: ['example.component.css'], | ||
| imports: [IonButton, IonButtons, IonContent, IonHeader, IonItem, IonLabel, IonList, IonModal, IonTitle, IonToolbar], | ||
| }) | ||
| export class ExampleComponent {} | ||
| ``` |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reorganizing the sections into Theming -> Styling to match other components, see: https://ionicframework.com/docs/api/action-sheet#theming
I considered updating the playground directory structure but moving any would break the JP docs.