Skip to content

Commit 79801e0

Browse files
crisbetommalerba
authored andcommitted
feat(button): align with 2018 material design spec (#13083)
Aligns the button component with the latest Material design spec. This includes the changes from #12537 and #13011.
1 parent 00b7233 commit 79801e0

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

src/lib/button/_button-base.scss

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@
66

77
// Flat and raised button standards
88
$mat-button-padding: 0 16px !default;
9-
$mat-button-min-width: 88px !default;
9+
$mat-button-min-width: 64px !default;
1010
$mat-button-margin: 0 !default;
1111
$mat-button-line-height: 36px !default;
12-
$mat-button-border-radius: 2px !default;
12+
$mat-button-border-radius: 4px !default;
1313
$mat-button-focus-transition: opacity 200ms $swift-ease-in-out-timing-function,
1414
background-color 200ms $swift-ease-in-out-timing-function !default;
1515

16-
// Stroked Button standards
17-
$mat-stroked-button-line-height: $mat-button-line-height - 2;
1816
// Stroked button padding is 1px less horizontally than default/flat/raised
1917
// button's padding.
18+
$mat-stroked-button-line-height: $mat-button-line-height - 2;
2019
$mat-stroked-button-padding: 0 15px;
2120

2221
// Icon Button standards
@@ -64,7 +63,7 @@ $mat-mini-fab-padding: 8px !default;
6463

6564
&.cdk-keyboard-focused, &.cdk-program-focused {
6665
.mat-button-focus-overlay {
67-
opacity: 1;
66+
opacity: 0.12;
6867
}
6968
}
7069

src/lib/button/_button-theme.scss

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
$warn: map-get($theme, warn);
1010

1111
&.mat-primary .mat-button-focus-overlay {
12-
background-color: mat-color($primary, 0.12);
12+
background-color: mat-color($primary);
1313
}
1414

1515
&.mat-accent .mat-button-focus-overlay {
16-
background-color: mat-color($accent, 0.12);
16+
background-color: mat-color($accent);
1717
}
1818

1919
&.mat-warn .mat-button-focus-overlay {
20-
background-color: mat-color($warn, 0.12);
20+
background-color: mat-color($warn);
2121
}
2222

2323
&[disabled] .mat-button-focus-overlay {
@@ -92,6 +92,16 @@
9292
@include _mat-button-ripple-color($theme, default);
9393
}
9494

95+
.mat-button-focus-overlay {
96+
background: map_get($foreground, base);
97+
}
98+
99+
// Note: this needs a bit extra specificity, because we're not guaranteed the inclusion
100+
// order of the theme styles and the button reset may end up resetting this as well.
101+
.mat-stroked-button:not(.mat-button-disabled) {
102+
border-color: mat-color($foreground, divider);
103+
}
104+
95105
.mat-flat-button, .mat-raised-button, .mat-fab, .mat-mini-fab {
96106
// Default font and background color when not using any color palette.
97107
color: mat-color($foreground, text);

src/lib/button/button.scss

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,45 @@
44
@import '../core/style/layout-common';
55
@import '../../cdk/a11y/a11y';
66

7-
.mat-button, .mat-icon-button, .mat-stroked-button, .mat-flat-button {
8-
@include mat-button-base;
9-
}
10-
117
.mat-button, .mat-icon-button {
128
.mat-button-focus-overlay {
13-
149
opacity: 0;
1510
}
1611
}
1712

1813
// Only flat and stroked buttons (not raised, FABs or icon buttons) have a hover style.
1914
// Use the same visual treatment for hover as for focus.
20-
.mat-button:hover .mat-button-focus-overlay,
21-
.mat-stroked-button:hover .mat-button-focus-overlay {
22-
opacity: 1;
15+
.mat-button:hover,
16+
.mat-stroked-button:hover {
17+
.mat-button-focus-overlay {
18+
opacity: 0.04;
19+
}
2320
}
2421

2522
// Disable the hover styles on non-hover devices. Since this is more of a progressive
2623
// enhancement and not all desktop browsers support this kind of media query, we can't
2724
// use something like `@media (hover)`.
2825
@media (hover: none) {
29-
.mat-button:hover .mat-button-focus-overlay,
30-
.mat-stroked-button:hover .mat-button-focus-overlay {
31-
opacity: 0;
26+
.mat-button:hover,
27+
.mat-stroked-button:hover {
28+
.mat-button-focus-overlay {
29+
opacity: 0;
30+
}
3231
}
3332
}
3433

34+
// Should be placed after the `:hover` styles so the focused
35+
// styling coming in from `mat-button-base` takes precedence.
36+
.mat-button, .mat-icon-button, .mat-stroked-button, .mat-flat-button {
37+
@include mat-button-base;
38+
}
39+
3540
.mat-raised-button {
3641
@include mat-raised-button;
3742
}
3843

3944
.mat-stroked-button {
40-
border: 1px solid currentColor;
45+
border: 1px solid currentColor;
4146
padding: $mat-stroked-button-padding;
4247
line-height: $mat-stroked-button-line-height;
4348
}
@@ -60,7 +65,6 @@
6065
height: $mat-icon-button-size;
6166

6267
flex-shrink: 0;
63-
6468
line-height: $mat-icon-button-size;
6569
border-radius: $mat-icon-button-border-radius;
6670

@@ -87,9 +91,6 @@
8791

8892
// Element that overlays the button to show focus and hover effects.
8993
.mat-button-focus-overlay {
90-
// The button spec calls for focus on raised buttons (and FABs) to be indicated with a
91-
// black, 12% opacity shade over the normal color (for both light and dark themes).
92-
background-color: rgba(black, 0.12);
9394
border-radius: inherit;
9495
opacity: 0;
9596

0 commit comments

Comments
 (0)