Skip to content

Commit 38edc9a

Browse files
committed
fix(material/icon): hides .mdc-button .mat-icon on mobile screens
Updates previous fix by updating documentation on the usage of mat-icon within mdc-button to notify developers that mat-icon is set to be hidden on mobile/xsmall screens to improve accessibility and recommends the usage of aria-label or aria-labelledby to notify screenreaders of the information that mat-icon is supposed to convey. Fixes b/250063405
1 parent d703746 commit 38edc9a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/material/icon/icon.md

+9
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ information as the icon.
117117
2. Add the `cdk-visually-hidden` class to the `<span>`. This will make the message invisible
118118
on-screen but still available to screen-reader users.
119119

120+
##### Interactive / Indicator icons within a button
121+
* *Note that when the presence of an icon in a button is supposed to communicate some
122+
information to the user or by being inlined into a block of text, as mentioned by
123+
Interactive icons above, an appropriate element should "own" the icon with interaction:
124+
* The `<mat-icon>` element should be a child of a `<button>` or `<a>` element.
125+
* The parent `<button>` or `<a>` should either have a meaningful label provided either through
126+
direct text content, `aria-label`, or `aria-labelledby`.
127+
* On mobile/small screens for these icons inlined with text in a button, the icon visibility is set to `hidden` to avoid overlapping into other elements and improve accessibility.
128+
120129
### Bidirectionality
121130

122131
By default icons in an RTL layout will look exactly the same as in LTR, however certain icons have

src/material/icon/icon.scss

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@use '../core/style/variables';
12
@use '../core/style/vendor-prefixes';
23
@use '../core/tokens/m2/mat/icon' as tokens-mat-icon;
34
@use '../core/tokens/token-utils';
@@ -81,3 +82,11 @@ mat-icon {
8182
word-spacing: 0;
8283
line-height: 1;
8384
}
85+
86+
// Makes button icon visibility hidden to fix b/250063405 to avoid
87+
// overrunning into sibling/neighboring elements.
88+
@media (variables.$xsmall) {
89+
.mdc-button .mat-icon {
90+
visibility: hidden;
91+
}
92+
}

0 commit comments

Comments
 (0)