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

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

Closed
PowerKiKi opened this issue Jul 19, 2021 · 8 comments · Fixed by #24578
Closed

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

PowerKiKi opened this issue Jul 19, 2021 · 8 comments · Fixed by #24578
Labels
area: material/icon needs: discussion Further discussion with the team is needed before proceeding P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@PowerKiKi
Copy link
Contributor

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, google/material-design-icons#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
@PowerKiKi PowerKiKi added the needs triage This issue needs to be triaged by the team label Jul 19, 2021
@PowerKiKi
Copy link
Contributor Author

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

@Totati
Copy link
Contributor

Totati commented Jul 19, 2021

I've used this workaround because a client wanted to copy a table's content into an excel sheet, and the icon's texts were pasted too.

@ivan-saorin
Copy link

This solution seems reasonable to me. 👍

@crisbeto
Copy link
Member

I believe that the text also has some accessibility implications.

@crisbeto crisbeto added area: material/icon needs: discussion Further discussion with the team is needed before proceeding P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent and removed needs triage This issue needs to be triaged by the team labels Jul 21, 2021
@Totati
Copy link
Contributor

Totati commented Jul 21, 2021

But only in english.

@PowerKiKi
Copy link
Contributor Author

I believe that the text also has some accessibility implications.

I don't think there is any impact on accessibility, since mat-icon does not have any accessibility features, as stated in the docs:

an icon alone does not convey any useful information for a screen-reader user. The user of <mat-icon> must provide additional information [...]

@crisbeto, shall I create a new PR for this ?

@davidecampello
Copy link

This also can help to acheive some sort of autocompletition in icon names.
If icon attribute is of type 'search', 'home', etc (all icon names), It can be very useful with IDE's autocomplete.
Of course it sould be updated every time an icon's name is updated or added.
A strongly type like fontawesome can also be very interesting...

.ts:

import { faCoffee } from '@fortawesome/free-solid-svg-icons';
...
  faCoffee = faCoffee;

template:

...
<fa-icon [icon]="faCoffee"></fa-icon>

PowerKiKi added a commit to PowerKiKi/material2 that referenced this issue Mar 11, 2022
The new way to use ligature icons, via a dedicated attribute, allow to hide
the font name from search engine results. Otherwise the font name, which was
never intended to be read by any end-users, would appear in the middle of legit
sentences in search results, thus making the search result very confusingto read.

New recommended usage is:

```diff
- <mat-icon>my-icon-name</mat-icon>
+ <mat-icon icon="my-icon-name"></mat-icon>
```

Fixes angular#23195
Fixes angular#23183
Fixes google/material-design-icons#498
PowerKiKi added a commit to PowerKiKi/material2 that referenced this issue Mar 11, 2022
The new way to use ligature icons, via a dedicated attribute, allow to hide
the font name from search engine results. Otherwise the font name, which was
never intended to be read by any end-users, would appear in the middle of legit
sentences in search results, thus making the search result very confusingto read.

New recommended usage is:

```diff
- <mat-icon>my-icon-name</mat-icon>
+ <mat-icon icon="my-icon-name"></mat-icon>
```

Fixes angular#23195
Fixes angular#23183
Fixes google/material-design-icons#498
PowerKiKi added a commit to PowerKiKi/material2 that referenced this issue Mar 11, 2022
The new way to use ligature icons, via a dedicated attribute, allow to hide
the font name from search engine results. Otherwise the font name, which was
never intended to be read by any end-users, would appear in the middle of legit
sentences in search results, thus making the search result very confusingto read.

New recommended usage is:

```diff
- <mat-icon>my-icon-name</mat-icon>
+ <mat-icon icon="my-icon-name"></mat-icon>
```

Fixes angular#23195
Fixes angular#23183
Fixes google/material-design-icons#498
PowerKiKi added a commit to PowerKiKi/material2 that referenced this issue Apr 1, 2022
The new way to use ligature icons, via a dedicated attribute, allows to hide
the font name from search engine results. Otherwise the font name, which was
never intended to be read by any end-users, would appear in the middle of legit
sentences in search results, thus making the search result very confusing to read.

New recommended usage is:

```diff
- <mat-icon>my-icon-name</mat-icon>
+ <mat-icon icon="my-icon-name"></mat-icon>
```

Fixes angular#23195
Fixes angular#23183
Fixes google/material-design-icons#498
PowerKiKi added a commit to PowerKiKi/material2 that referenced this issue Apr 1, 2022
The new way to use ligature icons, via a dedicated attribute, allows to hide
the font name from search engine results. Otherwise the font name, which was
never intended to be read by any end-users, would appear in the middle of legit
sentences in search results, thus making the search result very confusing to read.

New recommended usage is:

```diff
- <mat-icon>my-icon-name</mat-icon>
+ <mat-icon icon="my-icon-name"></mat-icon>
```

Fixes angular#23195
Fixes angular#23183
Fixes google/material-design-icons#498
PowerKiKi added a commit to PowerKiKi/material2 that referenced this issue Apr 1, 2022
The new way to use ligature icons, via a dedicated attribute, allows to hide
the font name from search engine results. Otherwise the font name, which was
never intended to be read by any end-users, would appear in the middle of legit
sentences in search results, thus making the search result very confusing to read.

New recommended usage is:

```diff
- <mat-icon>my-icon-name</mat-icon>
+ <mat-icon icon="my-icon-name"></mat-icon>
```

Fixes angular#23195
Fixes angular#23183
Fixes google/material-design-icons#498
PowerKiKi added a commit to PowerKiKi/material2 that referenced this issue Apr 1, 2022
The new way to use ligature icons, via a dedicated attribute, allows to hide
the font name from search engine results. Otherwise the font name, which was
never intended to be read by any end-users, would appear in the middle of legit
sentences in search results, thus making the search result very confusing to read.

New recommended usage is:

```diff
- <mat-icon>my-icon-name</mat-icon>
+ <mat-icon icon="my-icon-name"></mat-icon>
```

Fixes angular#23195
Fixes angular#23183
Fixes google/material-design-icons#498
PowerKiKi added a commit to PowerKiKi/material2 that referenced this issue Apr 2, 2022
The new way to use ligature icons, via the `fontIcon` attribute, allows to hide
the font name from search engine results. Otherwise, the font name, which was
never intended to be read by any end-users, would appear in the middle of legit
sentences in search results, thus making the search result very confusing to read.

New recommended usage is:

```diff
- <mat-icon>home</mat-icon>
+ <mat-icon fontIcon="home"></mat-icon>
```

To also enable this for custom font, include the special `ligature-font` class
when registering the font alias. So like this:

```ts
iconRegistry.registerFontClassAlias('f1', 'font1 ligature-font');
```

And use like this:

```html
<mat-icon fontSet="f1" fontIcon="home"></mat-icon>
```

Fixes angular#23195
Fixes angular#23183
Fixes google/material-design-icons#498
PowerKiKi added a commit to PowerKiKi/material2 that referenced this issue Apr 2, 2022
The new way to use ligature icons, via the `fontIcon` attribute, allows to hide
the font name from search engine results. Otherwise, the font name, which was
never intended to be read by any end-users, would appear in the middle of legit
sentences in search results, thus making the search result very confusing to read.

New recommended usage is:

```diff
- <mat-icon>home</mat-icon>
+ <mat-icon fontIcon="home"></mat-icon>
```

To also enable this for custom font, include the special `mat-ligature-font` class
when registering the font alias. So like this:

```ts
iconRegistry.registerFontClassAlias('f1', 'font1 mat-ligature-font');
```

And use like this:

```html
<mat-icon fontSet="f1" fontIcon="home"></mat-icon>
```

Fixes angular#23195
Fixes angular#23183
Fixes google/material-design-icons#498
PowerKiKi added a commit to PowerKiKi/material2 that referenced this issue Apr 2, 2022
The new way to use ligature icons, via the `fontIcon` attribute, allows to hide
the font name from search engine results. Otherwise, the font name, which was
never intended to be read by any end-users, would appear in the middle of legit
sentences in search results, thus making the search result very confusing to read.

New recommended usage is:

```diff
- <mat-icon>home</mat-icon>
+ <mat-icon fontIcon="home"></mat-icon>
```

To also enable this for custom font, include the special `mat-ligature-font` class
when registering the font alias. So like this:

```ts
iconRegistry.registerFontClassAlias('f1', 'font1 mat-ligature-font');
```

And use like this:

```html
<mat-icon fontSet="f1" fontIcon="home"></mat-icon>
```

Fixes angular#23195
Fixes angular#23183
Fixes google/material-design-icons#498
PowerKiKi added a commit to PowerKiKi/material2 that referenced this issue Apr 2, 2022
The new way to use ligature icons, via the `fontIcon` attribute, allows to hide
the font name from search engine results. Otherwise, the font name, which was
never intended to be read by any end-users, would appear in the middle of legit
sentences in search results, thus making the search result very confusing to read.

New recommended usage is:

```diff
- <mat-icon>home</mat-icon>
+ <mat-icon fontIcon="home"></mat-icon>
```

To also enable this for custom font, include the special `mat-ligature-font` class
when registering the font alias. So like this:

```ts
iconRegistry.registerFontClassAlias('f1', 'font1 mat-ligature-font');
```

And use like this:

```html
<mat-icon fontSet="f1" fontIcon="home"></mat-icon>
```

Fixes angular#23195
Fixes angular#23183
Fixes google/material-design-icons#498
andrewseguin pushed a commit that referenced this issue Jun 27, 2022
The new way to use ligature icons, via the `fontIcon` attribute, allows to hide
the font name from search engine results. Otherwise, the font name, which was
never intended to be read by any end-users, would appear in the middle of legit
sentences in search results, thus making the search result very confusing to read.

New recommended usage is:

```diff
- <mat-icon>home</mat-icon>
+ <mat-icon fontIcon="home"></mat-icon>
```

To also enable this for custom font, include the special `mat-ligature-font` class
when registering the font alias. So like this:

```ts
iconRegistry.registerFontClassAlias('f1', 'font1 mat-ligature-font');
```

And use like this:

```html
<mat-icon fontSet="f1" fontIcon="home"></mat-icon>
```

Fixes #23195
Fixes #23183
Fixes google/material-design-icons#498
andrewseguin pushed a commit that referenced this issue Jun 27, 2022
The new way to use ligature icons, via the `fontIcon` attribute, allows to hide
the font name from search engine results. Otherwise, the font name, which was
never intended to be read by any end-users, would appear in the middle of legit
sentences in search results, thus making the search result very confusing to read.

New recommended usage is:

```diff
- <mat-icon>home</mat-icon>
+ <mat-icon fontIcon="home"></mat-icon>
```

To also enable this for custom font, include the special `mat-ligature-font` class
when registering the font alias. So like this:

```ts
iconRegistry.registerFontClassAlias('f1', 'font1 mat-ligature-font');
```

And use like this:

```html
<mat-icon fontSet="f1" fontIcon="home"></mat-icon>
```

Fixes #23195
Fixes #23183
Fixes google/material-design-icons#498

(cherry picked from commit b37c96d)
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jul 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: material/icon needs: discussion Further discussion with the team is needed before proceeding P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants