Skip to content

Commit 11a3fe1

Browse files
crisbetojelbourn
authored andcommitted
feat(icon): add utility to mirror icons in RTL (#10327)
Adds the `mat-icon-rtl-mirror` CSS class that can be used to mirror icons only in an RTL layout. Fixes #10045.
1 parent b10fff4 commit 11a3fe1

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

src/demo-app/icon/icon-demo.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
<mat-icon svgIcon="thumb-up"></mat-icon>
1010
</p>
1111

12+
<p>
13+
Mirrored in RTL:
14+
<mat-icon class="mat-icon-rtl-mirror green" svgIcon="thumb-up"></mat-icon>
15+
<mat-icon class="mat-icon-rtl-mirror" svgIcon="thumb-up"></mat-icon>
16+
</p>
17+
1218
<p>
1319
From icon set:
1420
<mat-icon svgIcon="core:alarm"></mat-icon>

src/lib/icon/icon.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ explicitly set by calling `MatIconRegistry.setDefaultFontSetClass`.
3939
When an `mat-icon` component displays an SVG icon, it does so by directly inlining the SVG content
4040
into the page as a child of the component. (Rather than using an <img> tag or a div background
4141
image). This makes it easier to apply CSS styles to SVG icons. For example, the default color of the
42-
SVG content is the CSS
43-
[currentColor](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#currentColor_keyword)
44-
value. This makes SVG icons by default have the same color as surrounding text, and allows you to
42+
SVG content is the CSS
43+
[currentColor](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#currentColor_keyword)
44+
value. This makes SVG icons by default have the same color as surrounding text, and allows you to
4545
change the color by setting the "color" style on the `mat-icon` element.
4646

47-
In order to prevent XSS vulnerabilities, any SVG URLs passed to the `MatIconRegistry` must be
47+
In order to prevent XSS vulnerabilities, any SVG URLs passed to the `MatIconRegistry` must be
4848
marked as trusted resource URLs by using Angular's `DomSanitizer` service.
4949

50-
Also note that all SVG icons are fetched via XmlHttpRequest, and due to the same-origin policy,
51-
their URLs must be on the same domain as the containing page, or their servers must be configured
50+
Also note that all SVG icons are fetched via XmlHttpRequest, and due to the same-origin policy,
51+
their URLs must be on the same domain as the containing page, or their servers must be configured
5252
to allow cross-domain access.
5353

5454
#### Named icons
@@ -74,8 +74,8 @@ more than one icon set, the icon from the most recently registered set will be u
7474

7575
### Theming
7676

77-
By default, icons will use the current font color (`currentColor`). this color can be changed to
78-
match the current theme's colors using the `color` attribute. This can be changed to
77+
By default, icons will use the current font color (`currentColor`). this color can be changed to
78+
match the current theme's colors using the `color` attribute. This can be changed to
7979
`'primary'`, `'accent'`, or `'warn'`.
8080

8181
### Accessibility
@@ -91,6 +91,16 @@ In thinking about accessibility, it is useful to place icon use into one of thre
9191
2. **Interactive**: a user will click or otherwise interact with the icon to perform some action.
9292
3. **Indicator**: the icon is not interactive, but it conveys some information, such as a status.
9393

94+
### Bidirectionality
95+
96+
By default icons in an RTL layout will look exactly the same as in LTR, however certain icons have
97+
to be [mirrored for RTL users](https://material.io/guidelines/usability/bidirectionality.html). If
98+
you want to mirror an icon only in an RTL layout, you can use the `mat-icon-rtl-mirror` CSS class.
99+
100+
```html
101+
<mat-icon class="mat-icon-rtl-mirror" svgIcon="thumb-up"></mat-icon>
102+
```
103+
94104
#### Decorative icons
95105
When the icon is puely cosmetic and conveys no real semantic meaning, the `<mat-icon>` element
96106
should be marked with `aria-hidden="true"`.

src/lib/icon/icon.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ $mat-icon-size: 24px !default;
1919
}
2020
}
2121

22+
// Icons that will be mirrored in RTL.
23+
[dir='rtl'] .mat-icon-rtl-mirror {
24+
transform: scale(-1, 1);
25+
}
26+
2227
.mat-form-field:not(.mat-form-field-appearance-legacy) {
2328
.mat-form-field-prefix,
2429
.mat-form-field-suffix {

0 commit comments

Comments
 (0)