ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

[Ionic 2 feature] Overlays (Alert, Popover): cssClass option with support for multiple classes

Open szerner opened this issue 10 years ago • 8 comments

For a better and more flexible styling of my alert and popover overlays I would like to have the cssClass option supporting multiple classes. That could be in the form of concatenated class names or as an array of class names.

Now the cssClass supportes only one string token, any space character within results in runtime exceptions (InvalidCharacterError).

So cssClass="class-1 class-2" or cssClass=['class-1', 'class-2'] would be ideal.

Platform: Ionic 2 beta.11

Thank you!

szerner avatar Aug 09 '16 09:08 szerner

You currently can pass multiple classes, like so:

  doAlert() {
    let alert = this.alertCtrl.create({
      title: 'Alert',
      subTitle: 'Subtitle',
      message: 'This is an alert message.',
      buttons: ['OK'],
      cssClass: 'my-alert another-class'
    });

    alert.present();
  }

This should probably be documented better though. How are you currently trying to pass it?

brandyscarney avatar Aug 09 '16 17:08 brandyscarney

Thank you for looking into it. I only tried it with a Popover and

cssClass: "infopage mytheme"

which produces the following exception at runtime:

EXCEPTION: Error: Uncaught (in promise): EXCEPTION: Error in ./PopoverCmp class PopoverCmp_Host - inline template:0:0
ORIGINAL EXCEPTION: InvalidCharacterError: Failed to execute 'add' on 'DOMTokenList': The token provided ('infopage mytheme') contains HTML space characters, which are not valid in tokens.
....

I just checked my Alerts and they do fine with multiple classes, as you said. So this seems to be an Popover issue only.

szerner avatar Aug 09 '16 18:08 szerner

Thanks! I have added support for multiple classes to be passed to Popover, Action Sheet, Loading, and Toast components. It was already supported for the Alert and Picker components. I published a nightly version if you would like to test it out:

npm install --save [email protected]

brandyscarney avatar Aug 09 '16 21:08 brandyscarney

Nice, thank you! Now it works as expected, and I can declutter my SCSS...

szerner avatar Aug 10 '16 08:08 szerner

Awesome. I updated the documentation to reflect this. It will be in the beta 12 release. :)

brandyscarney avatar Aug 10 '16 15:08 brandyscarney

Hey, How about modals?

chack avatar Aug 14 '16 08:08 chack

how update the alert color with ionic 2 ??

karimambarek avatar Mar 10 '17 19:03 karimambarek

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

ionitron-bot[bot] avatar Sep 03 '18 19:09 ionitron-bot[bot]