Skip to content

Commit

Permalink
Also remove the ripple when transition is ended
Browse files Browse the repository at this point in the history
  • Loading branch information
tinayuangao committed Nov 17, 2016
1 parent 710278d commit 908862e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/lib/core/ripple/ripple-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ export class RippleRenderer {

/** Removes a foreground ripple from the DOM after it has faded out. */
removeRippleFromDom(ripple: Element) {
ripple.parentElement.removeChild(ripple);
if (ripple && ripple.parentElement) {
ripple.parentElement.removeChild(ripple);
}
}

/** Fades in the ripple background. */
Expand Down
10 changes: 9 additions & 1 deletion src/lib/core/ripple/ripple.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TestBed, ComponentFixture} from '@angular/core/testing';
import {TestBed, ComponentFixture, fakeAsync, tick} from '@angular/core/testing';
import {Component, ViewChild} from '@angular/core';
import {MdRipple, MdRippleModule} from './ripple';

Expand Down Expand Up @@ -128,6 +128,14 @@ describe('MdRipple', () => {
expect(rippleElement.querySelectorAll('.md-ripple-foreground').length).toBe(0);
});

it('removes foreground ripples after timeout', fakeAsync(() => {
rippleElement.click();
expect(rippleElement.querySelectorAll('.md-ripple-foreground').length).toBe(1);

tick(100);
expect(rippleElement.querySelectorAll('.md-ripple-foreground').length).toBe(0);
}));

it('creates ripples when manually triggered', () => {
const rippleComponent = fixture.debugElement.componentInstance.ripple;
// start() should show the background, but no foreground ripple yet.
Expand Down
1 change: 1 addition & 0 deletions src/lib/core/ripple/ripple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export class MdRipple implements OnInit, OnDestroy, OnChanges {
ripple.state = ForegroundRippleState.FADING_OUT;
break;
case ForegroundRippleState.FADING_OUT:
this._rippleRenderer.removeRippleFromDom(ripple.rippleElement);
break;
}
}
Expand Down

0 comments on commit 908862e

Please sign in to comment.