Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kktos opened this issue Apr 8, 2019 · 4 comments
Open

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

kktos opened this issue Apr 8, 2019 · 4 comments
Labels
area: material/icon feature This issue represents a new feature or feature request rather than a bug or bug fix P4 A relatively minor issue that is not relevant to core functions

Comments

@kktos
Copy link

kktos commented Apr 8, 2019

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();

@andrewseguin andrewseguin added feature This issue represents a new feature or feature request rather than a bug or bug fix P4 A relatively minor issue that is not relevant to core functions labels Apr 12, 2019
@jpike88
Copy link

jpike88 commented May 3, 2019

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
Copy link

wratho commented Feb 1, 2022

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
Copy link
Contributor

angular-robot bot commented Feb 21, 2022

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
Copy link
Contributor

angular-robot bot commented Mar 13, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: material/icon feature This issue represents a new feature or feature request rather than a bug or bug fix P4 A relatively minor issue that is not relevant to core functions
Projects
None yet
Development

No branches or pull requests

4 participants