Skip to content

Commit bb4c261

Browse files
committed
style(button): polished icon buttons ripples
1 parent 37e4bad commit bb4c261

File tree

4 files changed

+48
-13
lines changed

4 files changed

+48
-13
lines changed

src/lib/button/_button-theme.scss

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
@import '../core/theming/theming';
22

3-
43
// Applies a focus style to an md-button element for each of the supported palettes.
54
@mixin _mat-button-focus-color($theme) {
65
$primary: map-get($theme, primary);
@@ -20,6 +19,24 @@
2019
}
2120
}
2221

22+
@mixin _mat-button-ripple-color($theme) {
23+
$primary: map-get($theme, primary);
24+
$accent: map-get($theme, accent);
25+
$warn: map-get($theme, warn);
26+
27+
&.mat-primary .mat-ripple-element {
28+
background-color: mat-color($primary, 0.26);
29+
}
30+
31+
&.mat-accent .mat-ripple-element {
32+
background-color: mat-color($accent, 0.26);
33+
}
34+
35+
&.mat-warn .mat-ripple-element {
36+
background-color: mat-color($warn, 0.26);
37+
}
38+
}
39+
2340
// Applies a property to an md-button element for each of the supported palettes.
2441
@mixin _mat-button-theme-color($theme, $property, $color: 'default') {
2542
$primary: map-get($theme, primary);
@@ -70,6 +87,10 @@
7087
}
7188
}
7289

90+
.mat-icon-button {
91+
@include _mat-button-ripple-color($theme);
92+
}
93+
7394
.mat-raised-button, .mat-fab, .mat-mini-fab {
7495
// Default properties when not using any [color] value.
7596
color: mat-color($foreground, text);

src/lib/button/button.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<span class="mat-button-wrapper"><ng-content></ng-content></span>
22
<div md-ripple *ngIf="!_isRippleDisabled()" class="mat-button-ripple"
3-
[class.mat-button-ripple-round]="_isRoundButton()"
4-
[mdRippleTrigger]="_getHostElement()"></div>
3+
[mdRippleCentered]="_isIconButton()"
4+
[class.mat-button-ripple-round]="_isRoundButton() || _isIconButton()"
5+
[mdRippleTrigger]="_getHostElement()"></div>
56
<!-- the touchstart handler prevents the overlay from capturing the initial tap on touch devices -->
67
<div class="mat-button-focus-overlay" (touchstart)="$event.preventDefault()"></div>

src/lib/button/button.scss

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,24 @@
77
.mat-button, .mat-icon-button {
88
@extend %mat-button-base;
99

10-
// Only flat buttons and icon buttons (not raised or fabs) have a hover style.
11-
&:hover {
12-
// Use the same visual treatment for hover as for focus.
10+
&[disabled]:hover {
11+
&.mat-primary, &.mat-accent, &.mat-warn, .mat-button-focus-overlay {
12+
background-color: transparent;
13+
}
14+
1315
.mat-button-focus-overlay {
14-
opacity: 1;
16+
transition: none;
17+
opacity: 0;
1518
}
1619
}
20+
}
1721

18-
&[disabled]:hover {
19-
&.mat-primary, &.mat-accent, &.mat-warn, .mat-button-focus-overlay {
20-
background-color: transparent;
22+
.mat-button {
23+
// Only flat buttons (not raised, fabs or icon buttons) have a hover style.
24+
&:hover {
25+
// Use the same visual treatment for hover as for focus.
26+
.mat-button-focus-overlay {
27+
opacity: 1;
2128
}
2229
}
2330
}
@@ -74,6 +81,8 @@
7481
// element, however we use a proper DOM element in order to be able to disable the default
7582
// touch action. This makes the buttons more responsive on touch devices.
7683
.mat-button-focus-overlay {
84+
transition: opacity $swift-ease-in-duration $ease-in-out-curve-function,
85+
background-color $swift-ease-in-duration $ease-in-out-curve-function;
7786
// The button spec calls for focus on raised buttons (and FABs) to be indicated with a
7887
// black, 12% opacity shade over the normal color (for both light and dark themes).
7988
background-color: rgba(black, 0.12);

src/lib/button/button.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,13 @@ export class MdButton {
167167

168168
_isRoundButton() {
169169
const el = this._getHostElement();
170-
return el.hasAttribute('md-icon-button') ||
171-
el.hasAttribute('md-fab') ||
172-
el.hasAttribute('md-mini-fab');
170+
return el.hasAttribute('md-fab') ||
171+
el.hasAttribute('md-mini-fab');
172+
}
173+
174+
_isIconButton() {
175+
const el = this._getHostElement();
176+
return el.hasAttribute('md-icon-button');
173177
}
174178

175179
_isRippleDisabled() {

0 commit comments

Comments
 (0)