Skip to content

Commit 9664b46

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 3ad6ff0 commit 9664b46

File tree

5 files changed

+51
-15
lines changed

5 files changed

+51
-15
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);
@@ -24,6 +23,24 @@
2423
}
2524
}
2625

26+
@mixin _mat-button-ripple-color($theme) {
27+
$primary: map-get($theme, primary);
28+
$accent: map-get($theme, accent);
29+
$warn: map-get($theme, warn);
30+
31+
&.mat-primary .mat-ripple-element {
32+
background-color: mat-color($primary, 0.26);
33+
}
34+
35+
&.mat-accent .mat-ripple-element {
36+
background-color: mat-color($accent, 0.26);
37+
}
38+
39+
&.mat-warn .mat-ripple-element {
40+
background-color: mat-color($warn, 0.26);
41+
}
42+
}
43+
2744
// Applies a property to an md-button element for each of the supported palettes.
2845
@mixin _mat-button-theme-color($theme, $property, $color: 'default') {
2946
$primary: map-get($theme, primary);
@@ -69,6 +86,10 @@
6986
background: transparent;
7087
}
7188

89+
.mat-icon-button {
90+
@include _mat-button-ripple-color($theme);
91+
}
92+
7293
.mat-raised-button, .mat-fab, .mat-mini-fab {
7394
// Default properties when not using any [color] value.
7495
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: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
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-
}
9+
.mat-button-focus-overlay {
10+
transition: none;
11+
opacity: 0;
1612
}
1713
}
1814

15+
// Only flat buttons (not raised, fabs or icon buttons) have a hover style.
16+
// Use the same visual treatment for hover as for focus.
17+
.mat-button:hover .mat-button-focus-overlay {
18+
opacity: 1;
19+
}
20+
1921
.mat-raised-button {
2022
@extend %mat-raised-button;
2123
}

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)