Skip to content

Commit

Permalink
feat(modal): add cssClass to modal options
Browse files Browse the repository at this point in the history
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
  • Loading branch information
brandyscarney authored and manucorporat committed Apr 6, 2017
1 parent b07eb1a commit 5cb51ef
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/components/modal/modal-component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, ComponentFactoryResolver, HostListener, Renderer, ViewChild, ViewContainerRef } from '@angular/core';
import { Component, ComponentFactoryResolver, ElementRef, HostListener, Renderer, ViewChild, ViewContainerRef } from '@angular/core';

import { KEY_ESCAPE } from '../../platform/key';
import { NavParams } from '../../navigation/nav-params';
Expand Down Expand Up @@ -30,6 +30,7 @@ export class ModalCmp {
constructor(
public _cfr: ComponentFactoryResolver,
public _renderer: Renderer,
public _elementRef: ElementRef,
public _navParams: NavParams,
public _viewCtrl: ViewController,
gestureCtrl: GestureController,
Expand All @@ -43,6 +44,13 @@ export class ModalCmp {
disable: [GESTURE_MENU_SWIPE, GESTURE_GO_BACK_SWIPE]
});
this._bdDismiss = opts.enableBackdropDismiss;

if (opts.cssClass) {
opts.cssClass.split(' ').forEach((cssClass: string) => {
// Make sure the class isn't whitespace, otherwise it throws exceptions
if (cssClass.trim() !== '') _renderer.setElementClass(_elementRef.nativeElement, cssClass, true);
});
}
}

ionViewPreLoad() {
Expand Down
1 change: 1 addition & 0 deletions src/components/modal/modal-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export interface ModalOptions {
enableBackdropDismiss?: boolean;
enterAnimation?: string;
leaveAnimation?: string;
cssClass?: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.my-modal.my-blue-modal ion-content {
color: blue;
}
3 changes: 2 additions & 1 deletion src/components/modal/test/basic/pages/page-one/page-one.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export class PageOne {
presentModal() {
let modal = this.modalCtrl.create('ModalPassData', { userId: 8675309 }, {
enterAnimation: 'modal-slide-in',
leaveAnimation: 'modal-slide-out'
leaveAnimation: 'modal-slide-out',
cssClass: 'my-modal my-blue-modal'
});
modal.present();

Expand Down

0 comments on commit 5cb51ef

Please sign in to comment.