Skip to content

Commit 5cb51ef

Browse files
brandyscarneymanucorporat
authored andcommitted
feat(modal): add cssClass to modal options
Can pass one cssClass or multiple (same as out other overlays). Added a cssClass to the basic test which adds 2 classes and styles the font color of the content blue. Closes #10020
1 parent b07eb1a commit 5cb51ef

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

src/components/modal/modal-component.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, ComponentFactoryResolver, HostListener, Renderer, ViewChild, ViewContainerRef } from '@angular/core';
1+
import { Component, ComponentFactoryResolver, ElementRef, HostListener, Renderer, ViewChild, ViewContainerRef } from '@angular/core';
22

33
import { KEY_ESCAPE } from '../../platform/key';
44
import { NavParams } from '../../navigation/nav-params';
@@ -30,6 +30,7 @@ export class ModalCmp {
3030
constructor(
3131
public _cfr: ComponentFactoryResolver,
3232
public _renderer: Renderer,
33+
public _elementRef: ElementRef,
3334
public _navParams: NavParams,
3435
public _viewCtrl: ViewController,
3536
gestureCtrl: GestureController,
@@ -43,6 +44,13 @@ export class ModalCmp {
4344
disable: [GESTURE_MENU_SWIPE, GESTURE_GO_BACK_SWIPE]
4445
});
4546
this._bdDismiss = opts.enableBackdropDismiss;
47+
48+
if (opts.cssClass) {
49+
opts.cssClass.split(' ').forEach((cssClass: string) => {
50+
// Make sure the class isn't whitespace, otherwise it throws exceptions
51+
if (cssClass.trim() !== '') _renderer.setElementClass(_elementRef.nativeElement, cssClass, true);
52+
});
53+
}
4654
}
4755

4856
ionViewPreLoad() {

src/components/modal/modal-options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export interface ModalOptions {
44
enableBackdropDismiss?: boolean;
55
enterAnimation?: string;
66
leaveAnimation?: string;
7+
cssClass?: string;
78
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.my-modal.my-blue-modal ion-content {
2+
color: blue;
3+
}

src/components/modal/test/basic/pages/page-one/page-one.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ export class PageOne {
4343
presentModal() {
4444
let modal = this.modalCtrl.create('ModalPassData', { userId: 8675309 }, {
4545
enterAnimation: 'modal-slide-in',
46-
leaveAnimation: 'modal-slide-out'
46+
leaveAnimation: 'modal-slide-out',
47+
cssClass: 'my-modal my-blue-modal'
4748
});
4849
modal.present();
4950

0 commit comments

Comments
 (0)