Skip to content

Commit 75815cb

Browse files
committed
refactor(material/icon): simplifies icon style changes
Updates previous changes to icon.scss to remove unnecessary specificity targeting and just moves classes to be generalized under .mat-icon. Adds min-height and min-width to .mdc-button so that when buttons (with icons especially) do not allow its content to overflow outside of the button and maintaining its accessibility by not allowing overlapping of text/content. Fixes b/250063405
1 parent 93159b3 commit 75815cb

File tree

3 files changed

+6
-41
lines changed

3 files changed

+6
-41
lines changed

src/material/button/button.scss

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
align-items: center;
2424
justify-content: center;
2525
box-sizing: border-box;
26-
min-width: 64px;
26+
min-width: min-content;
27+
min-height: min-content;
2728
border: none;
2829
outline: none;
2930
line-height: inherit;

src/material/icon/icon.md

-9
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,6 @@ 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-
129120
### Bidirectionality
130121

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

src/material/icon/icon.scss

+4-31
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
@use '../core/style/variables';
21
@use '../core/style/vendor-prefixes';
32
@use '../core/tokens/m2/mat/icon' as tokens-mat-icon;
43
@use '../core/tokens/token-utils';
@@ -30,10 +29,6 @@ mat-icon {
3029
height: $size;
3130
width: $size;
3231

33-
// In some cases the icon elements may extend beyond the container. Clip these cases
34-
// in order to avoid weird overflows and click areas. See #11826.
35-
overflow: hidden;
36-
3732
&.mat-icon-inline {
3833
font-size: inherit;
3934
height: inherit;
@@ -44,6 +39,10 @@ mat-icon {
4439
&.mat-ligature-font[fontIcon]::before {
4540
content: attr(fontIcon);
4641
}
42+
43+
// Makes button icon overflow visible to fix b/250063405
44+
// Apply styles to avoid applying text-spacing to .mat-icon
45+
overflow: visible;
4746
}
4847

4948
// Icons that will be mirrored in RTL.
@@ -64,29 +63,3 @@ mat-icon {
6463
}
6564
}
6665
}
67-
68-
// Makes button icon overflow visible to fix b/250063405
69-
.mat-mdc-icon-button .mat-icon,
70-
.mdc-button .mat-icon,
71-
.mat-mdc-fab-base .mat-icon,
72-
.mat-toolbar .mat-icon,
73-
.mat-mdc-tooltip-trigger .mat-icon,
74-
.mat-mdc-tab .mat-icon,
75-
.mat-mdc-form-field .mat-icon,
76-
.mat-grid-tile .mat-icon,
77-
.mat-mdc-list-item .mat-icon,
78-
.mat-mdc-list-option .mat-icon {
79-
overflow: visible;
80-
// Apply styles to avoid text spacing
81-
letter-spacing: 0;
82-
word-spacing: 0;
83-
line-height: 1;
84-
}
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)