setShow2ndModal(false)}>
This is more modal content
setShow2ndModal(false)}>Close Modal
@@ -354,7 +397,8 @@ import { modalController } from '@ionic/core';
export class ModalExample {
async presentModal() {
const modal = await modalController.create({
- component: 'page-modal'
+ component: 'page-modal',
+ cssClass: 'my-custom-class'
});
await modal.present();
}
@@ -396,6 +440,7 @@ The previous example can be written to include data:
async presentModal() {
const modal = await modalController.create({
component: 'page-modal',
+ cssClass: 'my-custom-class',
componentProps: {
'firstName': 'Douglas',
'lastName': 'Adams',
@@ -466,6 +511,7 @@ export class ModalExample {
async presentModal() {
const modal = await modalController.create({
component: 'page-modal',
+ cssClass: 'my-custom-class',
swipeToClose: true,
presentingElement: this.el.closest('ion-router-outlet'),
});
@@ -481,6 +527,7 @@ In most scenarios, using the `ion-router-outlet` element as the `presentingEleme
async presentModal() {
const modal = await modalController.create({
component: 'page-modal',
+ cssClass: 'my-custom-class',
swipeToClose: true,
presentingElement: await modalController.getTop() // Get the top-most ion-modal
});
@@ -538,6 +585,7 @@ export default {
return this.$ionic.modalController
.create({
component: Modal,
+ cssClass: 'my-custom-class',
componentProps: {
data: {
content: 'New Content',
diff --git a/core/src/components/modal/usage/angular.md b/core/src/components/modal/usage/angular.md
index 3998fb5464..98db404510 100644
--- a/core/src/components/modal/usage/angular.md
+++ b/core/src/components/modal/usage/angular.md
@@ -15,7 +15,8 @@ export class ModalExample {
async presentModal() {
const modal = await this.modalController.create({
- component: ModalPage
+ component: ModalPage,
+ cssClass: 'my-custom-class'
});
return await modal.present();
}
@@ -44,6 +45,7 @@ The previous example can be written to include data:
async presentModal() {
const modal = await this.modalController.create({
component: ModalPage,
+ cssClass: 'my-custom-class',
componentProps: {
'firstName': 'Douglas',
'lastName': 'Adams',
@@ -138,6 +140,7 @@ constructor(private routerOutlet: IonRouterOutlet) {}
async presentModal() {
const modal = await this.modalController.create({
component: ModalPage,
+ cssClass: 'my-custom-class',
swipeToClose: true,
presentingElement: this.routerOutlet.nativeEl
});
@@ -155,9 +158,15 @@ constructor(private modalCtrl: ModalController) {}
async presentModal() {
const modal = await this.modalController.create({
component: ModalPage,
+ cssClass: 'my-custom-class',
swipeToClose: true,
presentingElement: await this.modalCtrl.getTop() // Get the top-most ion-modal
});
return await modal.present();
}
```
+
+
+### Style Placement
+
+In Angular, the CSS of a specific page is scoped only to elements of that page. Even though the Modal can be presented from within a page, the `ion-modal` element is appended outside of the current page. This means that any custom styles need to go in a global stylesheet file. In an Ionic Angular starter this can be the `src/global.scss` file or you can register a new global style file by [adding to the `styles` build option in `angular.json`](https://angular.io/guide/workspace-config#style-script-config).
diff --git a/core/src/components/modal/usage/javascript.md b/core/src/components/modal/usage/javascript.md
index ada96b6150..ce0e7a6c82 100644
--- a/core/src/components/modal/usage/javascript.md
+++ b/core/src/components/modal/usage/javascript.md
@@ -23,6 +23,7 @@ function presentModal() {
// create the modal with the `modal-page` component
const modalElement = document.createElement('ion-modal');
modalElement.component = 'modal-page';
+ modalElement.cssClass = 'my-custom-class';
// present the modal
document.body.appendChild(modalElement);
@@ -37,6 +38,7 @@ During creation of a modal, data can be passed in through the `componentProps`.
```javascript
const modalElement = document.createElement('ion-modal');
modalElement.component = 'modal-page';
+modalElement.cssClass = 'my-custom-class';
modalElement.componentProps = {
'firstName': 'Douglas',
'lastName': 'Adams',
@@ -85,6 +87,7 @@ Modals in iOS mode have the ability to be presented in a card-style and swiped t
```javascript
const modalElement = document.createElement('ion-modal');
modalElement.component = 'modal-page';
+modalElement.cssClass = 'my-custom-class';
modalElement.swipeToClose = true;
modalElement.presentingElement = document.querySelector('ion-nav');
```
@@ -94,6 +97,7 @@ In most scenarios, using the `ion-nav` element as the `presentingElement` is fin
```javascript
const modalElement = document.createElement('ion-modal');
modalElement.component = 'modal-page';
+modalElement.cssClass = 'my-custom-class';
modalElement.swipeToClose = true;
modalElement.presentingElement = await modalController.getTop(); // Get the top-most ion-modal
```
diff --git a/core/src/components/modal/usage/react.md b/core/src/components/modal/usage/react.md
index e4aaf7231a..85e70ddc95 100644
--- a/core/src/components/modal/usage/react.md
+++ b/core/src/components/modal/usage/react.md
@@ -7,7 +7,7 @@ export const ModalExample: React.FC = () => {
return (
-
+
This is modal content
setShowModal(false)}>Close Modal
@@ -22,10 +22,11 @@ export const ModalExample: React.FC = () => {
Modals in iOS mode have the ability to be presented in a card-style and swiped to close. The card-style presentation and swipe to close gesture are not mutually exclusive, meaning you can pick and choose which features you want to use. For example, you can have a card-style modal that cannot be swiped or a full sized modal that can be swiped.
```tsx
- setShowModal(false)}>
This is modal content
setShowModal(false)}>Close Modal
@@ -35,19 +36,21 @@ Modals in iOS mode have the ability to be presented in a card-style and swiped t
In most scenarios, setting a ref on `IonPage` and passing that ref's `current` value to `presentingElement` is fine. In cases where you are presenting a card-style modal from within another modal, you should pass in the top-most `ion-modal` ref as the `presentingElement`.
```tsx
- setShowModal(false)}>
This is modal content
setShow2ndModal(true)}>Show 2nd Modal
setShowModal(false)}>Close Modal
- setShow2ndModal(false)}>
This is more modal content
setShow2ndModal(false)}>Close Modal
diff --git a/core/src/components/modal/usage/stencil.md b/core/src/components/modal/usage/stencil.md
index aecf844a50..197b92bc40 100644
--- a/core/src/components/modal/usage/stencil.md
+++ b/core/src/components/modal/usage/stencil.md
@@ -10,7 +10,8 @@ import { modalController } from '@ionic/core';
export class ModalExample {
async presentModal() {
const modal = await modalController.create({
- component: 'page-modal'
+ component: 'page-modal',
+ cssClass: 'my-custom-class'
});
await modal.present();
}
@@ -52,6 +53,7 @@ The previous example can be written to include data:
async presentModal() {
const modal = await modalController.create({
component: 'page-modal',
+ cssClass: 'my-custom-class',
componentProps: {
'firstName': 'Douglas',
'lastName': 'Adams',
@@ -122,6 +124,7 @@ export class ModalExample {
async presentModal() {
const modal = await modalController.create({
component: 'page-modal',
+ cssClass: 'my-custom-class',
swipeToClose: true,
presentingElement: this.el.closest('ion-router-outlet'),
});
@@ -137,6 +140,7 @@ In most scenarios, using the `ion-router-outlet` element as the `presentingEleme
async presentModal() {
const modal = await modalController.create({
component: 'page-modal',
+ cssClass: 'my-custom-class',
swipeToClose: true,
presentingElement: await modalController.getTop() // Get the top-most ion-modal
});
diff --git a/core/src/components/modal/usage/vue.md b/core/src/components/modal/usage/vue.md
index fec97ab5ce..79e7884e70 100644
--- a/core/src/components/modal/usage/vue.md
+++ b/core/src/components/modal/usage/vue.md
@@ -45,6 +45,7 @@ export default {
return this.$ionic.modalController
.create({
component: Modal,
+ cssClass: 'my-custom-class',
componentProps: {
data: {
content: 'New Content',
diff --git a/core/src/components/popover/readme.md b/core/src/components/popover/readme.md
index 997680c687..7de1ca9bbb 100644
--- a/core/src/components/popover/readme.md
+++ b/core/src/components/popover/readme.md
@@ -6,6 +6,34 @@ A Popover is a dialog that appears on top of the current page. It can be used fo
To present a popover, call the `present` method on a popover instance. In order to position the popover relative to the element clicked, a click event needs to be passed into the options of the the `present` method. If the event is not passed, the popover will be positioned in the center of the viewport.
+### Customization
+
+Popover uses scoped encapsulation, which means it will automatically scope its CSS by appending each of the styles with an additional class at runtime. Overriding scoped selectors in CSS requires a [higher specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity) selector.
+
+We recommend passing a custom class to `cssClass` in the `create` method and using that to add custom styles to the host and inner elements. This property can also accept multiple classes separated by spaces. View the [Usage](#usage) section for an example of how to pass a class using `cssClass`.
+
+```css
+/* DOES NOT WORK - not specific enough */
+.popover-content {
+ background: #222;
+}
+
+/* Works - pass "my-custom-class" in cssClass to increase specificity */
+.my-custom-class .popover-content {
+ background: #222;
+}
+```
+
+Any of the defined [CSS Custom Properties](#css-custom-properties) can be used to style the Popover without needing to target individual elements:
+
+```css
+.my-custom-class {
+ --background: #222;
+}
+```
+
+> 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.
+
@@ -30,6 +58,7 @@ export class PopoverExample {
async presentPopover(ev: any) {
const popover = await this.popoverController.create({
component: PopoverComponent,
+ cssClass: 'my-custom-class',
event: ev,
translucent: true
});
@@ -39,12 +68,18 @@ export class PopoverExample {
```
+### Style Placement
+
+In Angular, the CSS of a specific page is scoped only to elements of that page. Even though the Popover can be presented from within a page, the `ion-popover` element is appended outside of the current page. This means that any custom styles need to go in a global stylesheet file. In an Ionic Angular starter this can be the `src/global.scss` file or you can register a new global style file by [adding to the `styles` build option in `angular.json`](https://angular.io/guide/workspace-config#style-script-config).
+
+
### Javascript
```javascript
function presentPopover(ev) {
const popover = Object.assign(document.createElement('ion-popover'), {
component: 'popover-example-page',
+ cssClass: 'my-custom-class',
event: ev,
translucent: true
});
@@ -67,6 +102,7 @@ export const PopoverExample: React.FC = () => {
<>
setShowPopover(false)}
>
This is popover content
@@ -93,6 +129,7 @@ export class PopoverExample {
async presentPopover(ev: any) {
const popover = await popoverController.create({
component: 'page-popover',
+ cssClass: 'my-custom-class',
event: ev,
translucent: true
});
diff --git a/core/src/components/popover/usage/angular.md b/core/src/components/popover/usage/angular.md
index 5e096f9938..4a8b082963 100644
--- a/core/src/components/popover/usage/angular.md
+++ b/core/src/components/popover/usage/angular.md
@@ -14,6 +14,7 @@ export class PopoverExample {
async presentPopover(ev: any) {
const popover = await this.popoverController.create({
component: PopoverComponent,
+ cssClass: 'my-custom-class',
event: ev,
translucent: true
});
@@ -21,3 +22,8 @@ export class PopoverExample {
}
}
```
+
+
+### Style Placement
+
+In Angular, the CSS of a specific page is scoped only to elements of that page. Even though the Popover can be presented from within a page, the `ion-popover` element is appended outside of the current page. This means that any custom styles need to go in a global stylesheet file. In an Ionic Angular starter this can be the `src/global.scss` file or you can register a new global style file by [adding to the `styles` build option in `angular.json`](https://angular.io/guide/workspace-config#style-script-config).
diff --git a/core/src/components/popover/usage/javascript.md b/core/src/components/popover/usage/javascript.md
index bbce90a448..548a236399 100644
--- a/core/src/components/popover/usage/javascript.md
+++ b/core/src/components/popover/usage/javascript.md
@@ -2,6 +2,7 @@
function presentPopover(ev) {
const popover = Object.assign(document.createElement('ion-popover'), {
component: 'popover-example-page',
+ cssClass: 'my-custom-class',
event: ev,
translucent: true
});
diff --git a/core/src/components/popover/usage/react.md b/core/src/components/popover/usage/react.md
index 237f938a11..9cde980381 100644
--- a/core/src/components/popover/usage/react.md
+++ b/core/src/components/popover/usage/react.md
@@ -9,6 +9,7 @@ export const PopoverExample: React.FC = () => {
<>
setShowPopover(false)}
>
This is popover content
diff --git a/core/src/components/popover/usage/stencil.md b/core/src/components/popover/usage/stencil.md
index e1c7746656..ed43652236 100644
--- a/core/src/components/popover/usage/stencil.md
+++ b/core/src/components/popover/usage/stencil.md
@@ -11,6 +11,7 @@ export class PopoverExample {
async presentPopover(ev: any) {
const popover = await popoverController.create({
component: 'page-popover',
+ cssClass: 'my-custom-class',
event: ev,
translucent: true
});