Skip to content

<ion-icon name="?"> elements won't be displayed in AlertController #18239

Closed

Description

@redwolf2

Ionic version:
[x] 4.x

I'm submitting a ...
[x] bug report
[ ] feature request

Current behavior:

ion-icon elements displayed in the AlertController won't show the icon, if the name attribute is used. SVG files with the src attributes work.

grafik

I am sure I saw this working in an older version of Ionic 4.

Related code:

ion-icon-bug.zip

import { AlertController } from '@ionic/angular';

public constructor(public alertController: AlertController) {

}

public async showInfoDialog() {
  const prompt = await this.alertController.create({
    header: 'name does not work, src does',
    message:
    '<div><ion-icon name="body"></ion-icon></div>' +
    '<div><ion-icon src="assets/icon/truck.svg"></ion-icon></div>',
     buttons: [{ text: 'OK' }]
   });
   await prompt.present();
}

Ionic info:

Ionic:

   ionic (Ionic CLI)             : 4.12.0 (C:\Users\user\AppData\Roaming\npm\node_modules\ionic)
   Ionic Framework               : @ionic/angular 4.4.0
   @angular-devkit/build-angular : 0.13.9
   @angular-devkit/schematics    : 7.3.9
   @angular/cli                  : 7.3.9
   @ionic/angular-toolkit        : 1.5.1

System:

   NodeJS : v10.15.3 (C:\Program Files\nodejs\node.exe)
   npm    : 6.4.1
   OS     : Windows 7

Activity

  1. added
    package: core
    type: bug
    on May 9, 2019
  2. brandyscarney commented on May 10, 2019

    @brandyscarney
    Member

    Thanks for the issue! I was able to confirm this: https://codepen.io/brandyscarney/pen/qGZydB?editors=1010

    The following error is being thrown: icon was not resolved

  3. topalavlad commented on May 11, 2019

    @topalavlad
    Contributor

    This happens because of how the message is sanitized:
    innerHTML={sanitizeDOMString(this.message)} which only allows the following attributes: const allowedAttributes = ['class', 'id', 'href', 'src']; and removes the others:

    message = "<div><ion-icon name="body"></ion-icon></div>"
    sanitizedMessage = "<div>Icon<ion-icon></ion-icon></div>";
    

    Another example is badge's slot attribute: https://codepen.io/Dudelozaur/pen/QREwJw
    You can see that the badges are placed differently on the alert than the initial page. Same thing happens for button shapes, setting items as disabled.

  4. redwolf2 commented on May 13, 2019

    @redwolf2
    Author

    @brandyscarney @topalavlad Thanks, now I understand the reason. Do you think there should be a way to pass unsanitized data to the modal?

  5. liamdebeasi commented on May 14, 2019

    @liamdebeasi
    Contributor

    Hi everyone,

    This issue has been resolved via #18246 and will be in the next version of Ionic. I added in the name and slot attributes to the allowed list of attributes since I felt those were commonly used attributes.

    In general, we don't add attributes to the allowed list of attributes. Components that allow HTML content like ion-alert are not intended for anything other than some basic HTML.

    I have created a feature request for giving users the option of bypassing the sanitizer if they need to do something complex: #18277

    Thanks!

  6. ionitron-bot commented on Jun 13, 2019

    @ionitron-bot

    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.

  7. locked and limited conversation to collaborators on Jun 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    package: coretype: bug

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions