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

feat(icon): add utility to mirror icons in RTL #10327

Merged
merged 1 commit into from
Mar 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/demo-app/icon/icon-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
<mat-icon svgIcon="thumb-up"></mat-icon>
</p>

<p>
Mirrored in RTL:
<mat-icon class="mat-icon-rtl-mirror green" svgIcon="thumb-up"></mat-icon>
<mat-icon class="mat-icon-rtl-mirror" svgIcon="thumb-up"></mat-icon>
</p>

<p>
From icon set:
<mat-icon svgIcon="core:alarm"></mat-icon>
Expand Down
26 changes: 18 additions & 8 deletions src/lib/icon/icon.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ explicitly set by calling `MatIconRegistry.setDefaultFontSetClass`.
When an `mat-icon` component displays an SVG icon, it does so by directly inlining the SVG content
into the page as a child of the component. (Rather than using an <img> tag or a div background
image). This makes it easier to apply CSS styles to SVG icons. For example, the default color of the
SVG content is the CSS
[currentColor](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#currentColor_keyword)
value. This makes SVG icons by default have the same color as surrounding text, and allows you to
SVG content is the CSS
[currentColor](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#currentColor_keyword)
value. This makes SVG icons by default have the same color as surrounding text, and allows you to
change the color by setting the "color" style on the `mat-icon` element.

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

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

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

### Theming

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

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

### Bidirectionality

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

```html
<mat-icon class="mat-icon-rtl-mirror" svgIcon="thumb-up"></mat-icon>
```

#### Decorative icons
When the icon is puely cosmetic and conveys no real semantic meaning, the `<mat-icon>` element
should be marked with `aria-hidden="true"`.
Expand Down
5 changes: 5 additions & 0 deletions src/lib/icon/icon.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ $mat-icon-size: 24px !default;
width: $mat-icon-size;
}

// Icons that will be mirrored in RTL.
[dir='rtl'] .mat-icon-rtl-mirror {
transform: scale(-1, 1);
}

.mat-form-field:not(.mat-form-field-appearance-legacy) {
.mat-form-field-prefix,
.mat-form-field-suffix {
Expand Down