Skip to content

Commit 97a7e2b

Browse files
crisbetojelbourn
authored andcommitted
docs(icon): add note about HttpClientModule requirement (#18070)
Adds a note to the icon docs that the `HttpClientModule` needs to be included. Also does some minor cleanup in the overview doc.
1 parent 2d866ae commit 97a7e2b

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/material/icon/icon.md

+18-13
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,25 @@ explicitly set by calling `MatIconRegistry.setDefaultFontSetClass`.
3737

3838
### SVG icons
3939

40-
When an `mat-icon` component displays an SVG icon, it does so by directly inlining the SVG content
41-
into the page as a child of the component. (Rather than using an `<img>` tag or a div background
42-
image). This makes it easier to apply CSS styles to SVG icons. For example, the default color of the
40+
`<mat-icon>` displays SVG icons by directly inlining the SVG content into the DOM
41+
as a child of itself. This approach offers an advantage over an `<img>` tag or a CSS
42+
`background-image` because it allows styling the SVG with CSS. For example, the default color of the
4343
SVG content is the CSS
4444
[currentColor](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#currentColor_keyword)
4545
value. This makes SVG icons by default have the same color as surrounding text, and allows you to
46-
change the color by setting the "color" style on the `mat-icon` element.
46+
change the color by setting the `color` style on the `mat-icon` element.
4747

48-
In order to prevent XSS vulnerabilities, any SVG URLs and HTML strings passed to the
48+
In order to guard against XSS vulnerabilities, any SVG URLs and HTML strings passed to the
4949
`MatIconRegistry` must be marked as trusted by using Angular's `DomSanitizer` service.
5050

51-
Also note that all SVG icons, registered by URL, are fetched via XmlHttpRequest, and due to the
52-
same-origin policy, their URLs must be on the same domain as the containing page, or their servers
53-
must be configured to allow cross-domain access.
51+
`MatIconRegistry` fetches all remote SVG icons via Angular's `HttpClient` service. If you haven't
52+
included [`HttpClientModule` from the `@angular/common/http` package](https://angular.io/guide/http)
53+
in your `NgModule` imports, you will get an error at runtime.
54+
55+
Note that `HttpClient` fetches SVG icons registered with a URL via `XmlHttpRequest`, subject to the
56+
[Same-origin policy](https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy). This
57+
means that icon URLs must have the same origin as the containing page or that the application's
58+
server must be configured to allow cross-origin requests.
5459

5560
#### Named icons
5661

@@ -92,8 +97,8 @@ element.
9297
In thinking about accessibility, it is useful to place icon use into one of three categories:
9398
1. **Decorative**: the icon conveys no real semantic meaning and is purely cosmetic.
9499
2. **Interactive**: a user will click or otherwise interact with the icon to perform some action.
95-
3. **Indicator**: the icon is not interactive, but it conveys some information, such as a status. This
96-
includes using the icon in place of text inside of a larger message.
100+
3. **Indicator**: the icon is not interactive, but it conveys some information, such as a status.
101+
This includes using the icon in place of text inside of a larger message.
97102

98103
#### Decorative icons
99104
When the icon is purely cosmetic and conveys no real semantic meaning, the `<mat-icon>` element
@@ -107,8 +112,8 @@ some icon on the page, a more appropriate element should "own" the interaction:
107112
direct text content, `aria-label`, or `aria-labelledby`.
108113

109114
#### Indicator icons
110-
When the presence of an icon communicates some information to the user whether as an indicator or
111-
by being inlined into a block of text, that information must also be made available to
115+
When the presence of an icon communicates some information to the user whether as an indicator or
116+
by being inlined into a block of text, that information must also be made available to
112117
screen-readers. The most straightforward way to do this is to
113118
1. Add a `<span>` as an adjacent sibling to the `<mat-icon>` element with text that conveys the same
114119
information as the icon.
@@ -118,7 +123,7 @@ on-screen but still available to screen-reader users.
118123
### Bidirectionality
119124

120125
By default icons in an RTL layout will look exactly the same as in LTR, however certain icons have
121-
to be [mirrored for RTL users](https://material.io/guidelines/usability/bidirectionality.html). If
126+
to be [mirrored for RTL users](https://material.io/design/usability/bidirectionality.html). If
122127
you want to mirror an icon only in an RTL layout, you can use the `mat-icon-rtl-mirror` CSS class.
123128

124129
```html

0 commit comments

Comments
 (0)