Skip to content

Commit c6e2f57

Browse files
committed
style(button): polished icon buttons ripples
- changed Icon button ripples to start from the center and removed hover style on icon buttons
1 parent aa3360a commit c6e2f57

File tree

5 files changed

+53
-17
lines changed

5 files changed

+53
-17
lines changed

src/lib/button/_button-base.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ $mat-button-min-width: 88px !default;
99
$mat-button-margin: 0 !default;
1010
$mat-button-line-height: 36px !default;
1111
$mat-button-border-radius: 2px !default;
12-
$mat-button-focus-transition: opacity 200ms $swift-ease-in-out-timing-function !default;
12+
$mat-button-focus-transition: opacity 200ms $swift-ease-in-out-timing-function,
13+
background-color 200ms $swift-ease-in-out-timing-function !default;
1314

1415
// Icon Button standards
1516
$mat-icon-button-size: 40px !default;

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+
[class.mat-button-ripple-round]="_isRoundButton || _isIconButton"
4+
[mdRippleCentered]="_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: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
// TODO(jelbourn): Measure perf benefits for translate3d and will-change.
22
// TODO(jelbourn): Figure out if anchor hover underline actually happens in any browser.
3-
43
@import 'button-base';
54
@import '../core/a11y/a11y';
65

76
.mat-button, .mat-icon-button {
87
@extend %mat-button-base;
98

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.
13-
.mat-button-focus-overlay {
14-
opacity: 1;
15-
}
16-
}
17-
189
&[disabled]:hover {
1910
&.mat-primary, &.mat-accent, &.mat-warn, .mat-button-focus-overlay {
2011
background-color: transparent;
2112
}
13+
14+
.mat-button-focus-overlay {
15+
transition: none;
16+
opacity: 0;
17+
}
2218
}
2319
}
2420

21+
// Only flat buttons (not raised, fabs or icon buttons) have a hover style.
22+
// Use the same visual treatment for hover as for focus.
23+
.mat-button:hover .mat-button-focus-overlay {
24+
opacity: 1;
25+
}
26+
2527
.mat-raised-button {
2628
@extend %mat-raised-button;
2729
}

src/lib/button/button.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ export class MdButton implements OnDestroy {
100100
private _color: string;
101101

102102
/** Whether the button is round. */
103-
_isRoundButton: boolean = ['icon-button', 'fab', 'mini-fab'].some(suffix => {
104-
let el = this._getHostElement();
105-
return el.hasAttribute('md-' + suffix) || el.hasAttribute('mat-' + suffix);
106-
});
103+
_isRoundButton: boolean = this._hasAttributeWithPrefix(['fab', 'mini-fab']);
104+
105+
/** Whether the button is icon button. */
106+
_isIconButton: boolean = this._hasAttributeWithPrefix(['icon-button']);
107107

108108
/** Whether the ripple effect on click should be disabled. */
109109
private _disableRipple: boolean = false;
@@ -157,6 +157,17 @@ export class MdButton implements OnDestroy {
157157
_isRippleDisabled() {
158158
return this.disableRipple || this.disabled;
159159
}
160+
161+
/** Gets whether the button has one of the given attributes
162+
* with either an 'md-' or 'mat-' prefix.
163+
*/
164+
_hasAttributeWithPrefix(unprefixedAttributeNames: string[]) {
165+
return unprefixedAttributeNames.some(suffix => {
166+
const el = this._getHostElement();
167+
168+
return el.hasAttribute('md-' + suffix) || el.hasAttribute('mat-' + suffix);
169+
});
170+
}
160171
}
161172

162173
/**

0 commit comments

Comments
 (0)