Skip to content

Commit aa404c5

Browse files
committed
fix(ripple): make ripples conform with specs
This makes the ripple service conform with the specifications and other Material reference implementations. See https://material.io/guidelines/motion/material-motion.html#material-motion-how-does-material-move This means the following: * Ripples now trigger on `mousedown` * Ripples now persists as long as the element is being hold. * No longer adds an unnecessary background ripple. * Removes the ugly `scale(0.00001)` for ripple animations Not only visually the ripple has been changed. The whole renderer has been rewritten and now has a very simple API, that can be easily used by developers. References #1434
1 parent 55b9224 commit aa404c5

16 files changed

+346
-655
lines changed

src/demo-app/ripple/ripple-demo.html

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,18 @@
2121
<section>
2222
Speed
2323
<md-radio-group [(ngModel)]="rippleSpeed">
24-
<md-radio-button name="demo-ripple-options" value="0.1">Slow</md-radio-button>
24+
<md-radio-button name="demo-ripple-options" value="0.4">Slow</md-radio-button>
2525
<md-radio-button name="demo-ripple-options" value="1">Normal</md-radio-button>
26-
<md-radio-button name="demo-ripple-options" value="4">Fast</md-radio-button>
26+
<md-radio-button name="demo-ripple-options" value="2.5">Fast</md-radio-button>
2727
</md-radio-group>
2828
</section>
2929
<section>
3030
<md-input-container>
31-
<input mdInput placeholder="Max radius" aria-label="radius" [(ngModel)]="maxRadius">
31+
<input mdInput placeholder="Ripple radius" aria-label="radius" [(ngModel)]="radius">
3232
</md-input-container>
3333
<md-input-container>
3434
<input mdInput placeholder="Ripple color" aria-label="color" [(ngModel)]="rippleColor">
3535
</md-input-container>
36-
<md-input-container>
37-
<input mdInput
38-
placeholder="Ripple background"
39-
aria-label="background"
40-
[(ngModel)]="rippleBackgroundColor">
41-
</md-input-container>
4236
</section>
4337
<section>
4438
<button md-raised-button (click)="doManualRipple()">Manual ripple</button>
@@ -51,9 +45,8 @@
5145
[mdRippleCentered]="centered"
5246
[mdRippleDisabled]="disabled"
5347
[mdRippleUnbounded]="unbounded"
54-
[mdRippleMaxRadius]="maxRadius"
48+
[mdRippleRadius]="radius"
5549
[mdRippleColor]="rippleColor"
56-
[mdRippleBackgroundColor]="rippleBackgroundColor"
5750
[mdRippleSpeedFactor]="rippleSpeed">
5851
Click me
5952
</div>

src/demo-app/ripple/ripple-demo.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,22 @@ import {MdRipple} from '@angular/material';
99
styleUrls: ['ripple-demo.css'],
1010
})
1111
export class RippleDemo {
12-
@ViewChild(MdRipple) manualRipple: MdRipple;
12+
@ViewChild(MdRipple) ripple: MdRipple;
1313

1414
centered = false;
1515
disabled = false;
1616
unbounded = false;
1717
rounded = false;
18-
maxRadius: number = null;
18+
radius: number = null;
1919
rippleSpeed = 1;
2020
rippleColor = '';
21-
rippleBackgroundColor = '';
2221

2322
disableButtonRipples = false;
2423

2524
doManualRipple() {
26-
if (this.manualRipple) {
27-
window.setTimeout(() => this.manualRipple.start(), 10);
28-
window.setTimeout(() => this.manualRipple.end(0, 0), 500);
25+
if (this.ripple) {
26+
this.ripple.createRipple(0, 0, { centered: true });
2927
}
3028
}
29+
3130
}

src/lib/button/button.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<span class="md-button-wrapper"><ng-content></ng-content></span>
22
<div md-ripple *ngIf="!_isRippleDisabled()" class="md-button-ripple"
33
[class.md-button-ripple-round]="_isRoundButton()"
4-
[mdRippleTrigger]="_getHostElement()"
5-
[mdRippleColor]="_isRoundButton() ? 'rgba(255, 255, 255, 0.2)' : ''"
6-
mdRippleBackgroundColor="rgba(0, 0, 0, 0)"></div>
4+
[mdRippleTrigger]="_getHostElement()"></div>
75
<!-- the touchstart handler prevents the overlay from capturing the initial tap on touch devices -->
86
<div class="md-button-focus-overlay" (touchstart)="$event.preventDefault()"></div>

src/lib/checkbox/_checkbox-theme.scss

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,16 @@
6868
}
6969
}
7070

71-
.md-checkbox:not(.md-checkbox-disabled) {
72-
&.md-primary .md-checkbox-ripple .md-ripple-foreground {
71+
md-checkbox:not(.md-checkbox-disabled) {
72+
&.md-primary .md-checkbox-ripple .md-ripple-element {
7373
background-color: md-color($primary, 0.26);
7474
}
7575

76-
&.md-accent .md-checkbox-ripple .md-ripple-foreground {
76+
&.md-accent .md-checkbox-ripple .md-ripple-element {
7777
background-color: md-color($accent, 0.26);
7878
}
7979

80-
&.md-warn .md-checkbox-ripple .md-ripple-foreground {
80+
&.md-warn .md-checkbox-ripple .md-ripple-element {
8181
background-color: md-color($warn, 0.26);
8282
}
8383
}

src/lib/checkbox/checkbox.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
<div md-ripple *ngIf="!_isRippleDisabled()" class="md-checkbox-ripple"
1919
[mdRippleTrigger]="_getHostElement()"
2020
[mdRippleCentered]="true"
21-
[mdRippleSpeedFactor]="0.3"
22-
mdRippleBackgroundColor="rgba(0, 0, 0, 0)"></div>
21+
[mdRippleSpeedFactor]="0.3"></div>
2322
<div class="md-checkbox-frame"></div>
2423
<div class="md-checkbox-background">
2524
<svg version="1.1"

src/lib/core/option/option.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<ng-content></ng-content>
2-
<div class="md-option-ripple" *ngIf="!disabled" md-ripple mdRippleBackgroundColor="rgba(0,0,0,0)"
2+
<div class="md-option-ripple" *ngIf="!disabled" md-ripple
33
[mdRippleTrigger]="_getHostElement()"></div>

src/lib/core/ripple/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ Properties:
1919
| --- | --- | --- |
2020
| `mdRippleTrigger` | Element | The DOM element that triggers the ripple when clicked. Defaults to the parent of the `md-ripple`.
2121
| `mdRippleColor` | string | Custom color for foreground ripples
22-
| `mdRippleBackgroundColor` | string | Custom color for the ripple background
2322
| `mdRippleCentered` | boolean | If true, the ripple animation originates from the center of the `md-ripple` bounds rather than from the location of the click event.
24-
| `mdRippleMaxRadius` | number | Optional fixed radius of foreground ripples when fully expanded. Mainly used in conjunction with `unbounded` attribute. If not set, ripples will expand from their origin to the most distant corner of the component's bounding rectangle.
23+
| `mdRippleRadius` | number | Optional fixed radius of foreground ripples when fully expanded. Mainly used in conjunction with `unbounded` attribute. If not set, ripples will expand from their origin to the most distant corner of the component's bounding rectangle.
2524
| `mdRippleUnbounded` | boolean | If true, foreground ripples will be visible outside the component's bounds.
26-
| `mdRippleFocused` | boolean | If true, the background ripple is shown using the current theme's accent color to indicate focus.
2725
| `mdRippleDisabled` | boolean | If true, click events on the trigger element will not activate ripples. The `start` and `end` methods can still be called to programmatically create ripples.

src/lib/core/ripple/_ripple.scss

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

3-
4-
$md-ripple-focused-opacity: 0.1;
5-
$md-ripple-background-fade-duration: 300ms;
6-
$md-ripple-background-default-color: rgba(0, 0, 0, 0.0588);
7-
$md-ripple-foreground-initial-opacity: 0.25;
8-
$md-ripple-foreground-default-color: rgba(0, 0, 0, 0.0588);
3+
$md-ripple-element-color: rgba(0, 0, 0, 0.1);
94

105

116
@mixin md-ripple() {
@@ -19,55 +14,19 @@ $md-ripple-foreground-default-color: rgba(0, 0, 0, 0.0588);
1914
overflow: visible;
2015
}
2116

22-
.md-ripple-background {
23-
background-color: $md-ripple-background-default-color;
24-
opacity: 0;
25-
transition: opacity $md-ripple-background-fade-duration linear;
17+
.md-ripple-element {
2618
position: absolute;
27-
left: 0;
28-
top: 0;
29-
right: 0;
30-
bottom: 0;
31-
}
32-
33-
.md-ripple-unbounded .md-ripple-background {
34-
display: none;
35-
}
36-
37-
.md-ripple-background.md-ripple-active {
38-
opacity: 1;
39-
}
40-
41-
.md-ripple-focused .md-ripple-background {
42-
opacity: 1;
43-
}
44-
45-
.md-ripple-foreground {
46-
background-color: $md-ripple-foreground-default-color;
4719
border-radius: 50%;
4820
pointer-events: none;
49-
opacity: $md-ripple-foreground-initial-opacity;
50-
position: absolute;
51-
// The transition duration is manually set based on the ripple size.
52-
transition: opacity, transform 0ms cubic-bezier(0, 0, 0.2, 1);
53-
}
5421

55-
.md-ripple-foreground.md-ripple-fade-in {
56-
opacity: 1;
57-
}
22+
background-color: $md-ripple-element-color;
5823

59-
.md-ripple-foreground.md-ripple-fade-out {
60-
opacity: 0;
24+
transition: opacity, transform 0ms cubic-bezier(0, 0, 0.2, 1);
25+
transform: scale(0);
6126
}
6227
}
6328

64-
@mixin md-ripple-theme($theme) {
65-
$accent: map-get($theme, accent);
66-
67-
.md-ripple-focused .md-ripple-background {
68-
background-color: md-color($accent, $md-ripple-focused-opacity);
69-
}
70-
}
29+
@mixin md-ripple-theme($theme) {}
7130

7231

7332
// A mixin, which generates temporary ink ripple on a given component.

0 commit comments

Comments
 (0)