Skip to content

Commit 4c75bad

Browse files
committed
feat(button): align with 2018 material design spec
Aligns the button component with the latest Material design spec. Includes moving away from centering with `line-height`, in favor of using flexbox. Using the `line-height` ends up being fiddly and isn't quite centered in some cases like the stroked buttons.
1 parent 1e1751f commit 4c75bad

File tree

4 files changed

+31
-43
lines changed

4 files changed

+31
-43
lines changed

src/lib/button/_button-base.scss

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,26 @@
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;
11-
$mat-button-line-height: 36px !default;
12-
$mat-button-border-radius: 2px !default;
11+
$mat-button-height: 36px !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.
2018
$mat-stroked-button-padding: 0 15px;
2119

2220
// Icon Button standards
2321
$mat-icon-button-size: 40px !default;
2422
$mat-icon-button-border-radius: 50% !default;
25-
$mat-icon-button-line-height: 24px !default;
2623

2724
// Fab standards
2825
$mat-fab-border-radius: 50% !default;
2926
$mat-fab-size: 56px !default;
30-
$mat-fab-padding: 16px !default;
3127

3228
$mat-mini-fab-size: 40px !default;
33-
$mat-mini-fab-padding: 8px !default;
3429

3530
// Applies base styles to all button types.
3631
@mixin mat-button-base {
@@ -44,15 +39,16 @@ $mat-mini-fab-padding: 8px !default;
4439
display: inline-block;
4540
white-space: nowrap;
4641
text-decoration: none;
47-
vertical-align: baseline;
42+
vertical-align: middle;
4843
text-align: center;
4944

5045
// Sizing.
5146
margin: $mat-button-margin;
5247
min-width: $mat-button-min-width;
53-
line-height: $mat-button-line-height;
48+
height: $mat-button-height;
5449
padding: $mat-button-padding;
5550
border-radius: $mat-button-border-radius;
51+
letter-spacing: 0.08929em;
5652

5753
// Explicitly set the default overflow to `visible`. It is already set
5854
// on most browsers except on IE11 where it defaults to `hidden`.
@@ -64,7 +60,7 @@ $mat-mini-fab-padding: 8px !default;
6460

6561
&.cdk-keyboard-focused, &.cdk-program-focused {
6662
.mat-button-focus-overlay {
67-
opacity: 1;
63+
opacity: 0.12;
6864
}
6965
}
7066

@@ -96,7 +92,7 @@ $mat-mini-fab-padding: 8px !default;
9692
}
9793

9894
// Applies styles to fab and mini-fab button types only
99-
@mixin mat-fab($size, $padding) {
95+
@mixin mat-fab($size) {
10096
@include mat-raised-button;
10197
@include mat-overridable-elevation(6);
10298

@@ -113,10 +109,4 @@ $mat-mini-fab-padding: 8px !default;
113109
&:not([disabled]):active {
114110
@include mat-overridable-elevation(12);
115111
}
116-
117-
.mat-button-wrapper {
118-
padding: $padding 0;
119-
display: inline-block;
120-
line-height: $mat-icon-button-line-height;
121-
}
122112
}

src/lib/button/_button-theme.scss

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

1010
&.mat-primary .mat-button-focus-overlay {
11-
background-color: mat-color($primary, 0.12);
11+
background-color: mat-color($primary);
1212
}
1313

1414
&.mat-accent .mat-button-focus-overlay {
15-
background-color: mat-color($accent, 0.12);
15+
background-color: mat-color($accent);
1616
}
1717

1818
&.mat-warn .mat-button-focus-overlay {
19-
background-color: mat-color($warn, 0.12);
19+
background-color: mat-color($warn);
2020
}
2121

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

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

src/lib/button/button.scss

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// Use the same visual treatment for hover as for focus.
2020
.mat-button:hover .mat-button-focus-overlay,
2121
.mat-stroked-button:hover .mat-button-focus-overlay {
22-
opacity: 1;
22+
opacity: 0.04;
2323
}
2424

2525
// Disable the hover styles on non-hover devices. Since this is more of a progressive
@@ -38,22 +38,20 @@
3838

3939
.mat-stroked-button {
4040
@include mat-overridable-elevation(0);
41-
42-
border: 1px solid currentColor;
4341
padding: $mat-stroked-button-padding;
44-
line-height: $mat-stroked-button-line-height;
42+
border: solid 1px currentColor;
4543
}
4644

4745
.mat-flat-button {
4846
@include mat-overridable-elevation(0);
4947
}
5048

5149
.mat-fab {
52-
@include mat-fab($mat-fab-size, $mat-fab-padding);
50+
@include mat-fab($mat-fab-size);
5351
}
5452

5553
.mat-mini-fab {
56-
@include mat-fab($mat-mini-fab-size, $mat-mini-fab-padding);
54+
@include mat-fab($mat-mini-fab-size);
5755
}
5856

5957
.mat-icon-button {
@@ -66,13 +64,7 @@
6664
height: $mat-icon-button-size;
6765

6866
flex-shrink: 0;
69-
70-
line-height: $mat-icon-button-size;
7167
border-radius: $mat-icon-button-border-radius;
72-
73-
i, .mat-icon {
74-
line-height: $mat-icon-button-line-height;
75-
}
7668
}
7769

7870
// The ripple container and focus overlay should match the bounds of the entire button.
@@ -93,9 +85,6 @@
9385

9486
// Element that overlays the button to show focus and hover effects.
9587
.mat-button-focus-overlay {
96-
// The button spec calls for focus on raised buttons (and FABs) to be indicated with a
97-
// black, 12% opacity shade over the normal color (for both light and dark themes).
98-
background-color: rgba(black, 0.12);
9988
border-radius: inherit;
10089
opacity: 0;
10190

@@ -121,12 +110,12 @@
121110
z-index: 1;
122111
}
123112

124-
// Elements inside of all type of buttons should be vertical aligned in the middle.
125-
.mat-button, .mat-flat-button, .mat-stroked-button, .mat-raised-button, .mat-icon-button,
126-
.mat-fab, .mat-mini-fab {
127-
.mat-button-wrapper > * {
128-
vertical-align: middle;
129-
}
113+
.mat-button-wrapper {
114+
display: flex;
115+
width: 100%;
116+
height: 100%;
117+
align-items: center;
118+
justify-content: center;
130119
}
131120

132121
// Align icon-buttons correctly inside of standard, fill, and outline form-field appearances.

src/lib/form-field/form-field-legacy.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ $mat-form-field-legacy-underline-height: 1px !default;
2525
// Allow icon buttons in a prefix or suffix to adapt to the correct size.
2626
.mat-icon-button {
2727
font: inherit;
28-
vertical-align: baseline;
2928

3029
.mat-icon {
3130
font-size: inherit;

0 commit comments

Comments
 (0)