angular / components

Component infrastructure and Material Design components for Angular
https://material.angular.io
MIT License
24.23k stars 6.7k forks source link

mat-icon: To be able to have both svgIcon and fontIcon #15751

Open kktos opened 5 years ago

kktos commented 5 years ago

Please describe the feature you would like to request.

Let's say you have a js structure (an array of object) holding a list of icons, some svg, some font with other properties. In your view you want to have a simple *ngFor to iterate on all your icons. For svg icons, your object will have a "svg" property. For font icons, your object will have a "font" property. The key will be undefined if not set. Therefore, you will have in your loop something like: <mat-icon [matTooltip]="btn.tooltip | translate" [svgIcon]="btn.svgicon">{{ btn.icon }}</mat-icon> Sounds pretty easy but that's not working right now (Angular Material 7.3.7).

What is the use-case or motivation for this proposal?

To simply KISS To avoid a fugly: <mat-icon *ngIf="btn.svgicon" [matTooltip]="btn.tooltip | translate" [svgIcon]="btn.svgicon"></mat-icon> <mat-icon *ngIf="!btn.svgicon" [matTooltip]="btn.tooltip | translate">{{ btn.icon }}</mat-icon>

Is there anything else we should know?

For what I saw, the reason about that is located in: https://github.com/angular/material2/blob/master/src/lib/icon/icon.ts#L224-L244

A quick hack could be : https://github.com/angular/material2/blob/master/src/lib/icon/icon.ts#L237 !this._usingFontIcon() && this._clearSvgElement();

jpike88 commented 5 years ago

This is becoming a huge pain, I want to mix in a few svgs that are multi-colour and therefore not fit for ligature usage.

What really should be done is a check for whether that svgIcon item exists in the matIconRegistry, and a fallback to ligatures if it doesn't.

wratho commented 2 years ago

This is how we accomplish it

<mat-icon [svgIcon]="item.useSVG ? item.icon : ''">
  <ng-container *ngIf="!item.useSVG">{{item.icon}}</ng-container>
</mat-icon>

it's not much better, i would love for the svgIcon input to gracefully fail and fallback to the provided ligature and if both fail just display nothing. Maybe a console warning if you must do something, but I'm not sure it's needed. surely seeing that an icon wasn't displayed would be error enough.

angular-robot[bot] commented 2 years ago

Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

Find more details about Angular's feature request process in our documentation.

angular-robot[bot] commented 2 years ago

Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.

We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

You can find more details about the feature request process in our documentation.