question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug(mat-icon): Font icon names are indexed by search engines

See original GitHub issue

Reproduction

https://stackblitz.com/edit/angular-gkwffm?file=src%2Fapp%2Ficon-overview-example.html

Steps to reproduce:

  1. Open stackblitz
  2. Select all with ctrl+a
  3. See that the original icon is selected, hence indexed by search engine (bad)
  4. See that the new icon is not selected, hence not indexed by search engine (good)

Expected Behavior

When I use a <mat-icon> I expected that the icon name is never indexed in search engine result. And that should be the case for all forms of <mat-icon>.

Actual Behavior

When I use the form <mat-icon>home</mat-icon> the text home will appear in search result pages (eg: on google.com), but this text has no value at all, and might even be counter-productive, because the icon name does not necessarily match the app specific semantic. More generally, the configuration of an Angular component should not end up on Google search results (or any other search engines).

There is a related issue, https://github.com/google/material-design-icons/issues/498, where a workaround is mentioned. It is to use the attribute data-nosnippet, as detailed in https://developers.google.com/search/docs/advanced/crawling/special-tags#data-nosnippet. But as far as I know, this only works for Google. And it must be used manually on every single usage of <mat-icon>, which is error prone.

Proposed Solution

I think we should have a more robust solution baked in <mat-icon>, as described in that issue, by using thee CSS attr() function. So new usage would be something similar to:

- <mat-icon>home</mat-icon>
+ <mat-icon icon="home"></mat-icon>

The only thing to change in <mat-icon> itself is to add the following CSS:

.mat-icon:after {
    content: attr(icon);
}

This would make the API more consistent with all possible usages being:

<mat-icon>home</mat-icon>      <= Maybe deprecate this later ?
<mat-icon icon="home"></mat-icon>
<mat-icon svgIcon="left-arrow"></mat-icon>
<mat-icon fontSet="fa" fontIcon="alarm"></mat-icon>

From the accessibility point of view, and according to https://material.angular.io/components/icon/overview#accessibility, I don’t think it would change anything.

And because we don’t hardcode anything about the font in CSS, the CSS weight increase is minimal, and it does not have to be maintained when the font changes.

I would be willing to create a PR for this, as long as there is a chance to get merged. So would this be acceptable ?

Environment

  • Angular: 12.1
  • CDK/Material: 12.1
  • Browser(s): irrelevant
  • Operating System (e.g. Windows, macOS, Ubuntu): irrelevant

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:6
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
ivan-saorincommented, Jul 19, 2021

This solution seems reasonable to me. 👍

2reactions
PowerKiKicommented, Jul 19, 2021

Oh, this would also solve #23183 at the same time, since icons become CSS selectable (and thus customizable).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular Material icons not working - Stack Overflow
I have angular 9 project and after import material icon font file in .scss, still same issue, material icon is not visible, it...
Read more >
Mat-Icon List : 900+ Angular Material Icons
mat-icon selector used to display Material icons in Angular.We have around 900+ Angular Material icons.To show the below mat-icon list icons ...
Read more >
Icon | Angular Material
Sets the CSS classes to be used for icon fonts when an <mat-icon> component does not have a fontSet input value, and is...
Read more >
material-icons - npm
Latest icon fonts and CSS for self-hosting material design icons. This package is automatically updated, so it will always have the latest icons...
Read more >
How to Use Angular 11 Material Font Icons - Developer.com
Material font icons can greatly enhance user experience. ... <title>Angular MatIcons Tutorial</title> <base href="/"> <meta name="viewport" ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found