Skip to content

Commit

Permalink
fix(ripple): Clean activation timer and css when interrupted (#2490)
Browse files Browse the repository at this point in the history
  • Loading branch information
deilv authored and kfranqueiro committed Apr 3, 2018
1 parent 306fd7f commit 18cba98
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/mdc-ripple/foundation.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ class MDCRippleFoundation extends MDCFoundation {
if (!this.isSupported_()) {
return;
}

if (this.activationTimer_) {
clearTimeout(this.activationTimer_);
this.activationTimer_ = 0;
const {FG_ACTIVATION} = MDCRippleFoundation.cssClasses;
this.adapter_.removeClass(FG_ACTIVATION);
}

this.deregisterRootHandlers_();
this.deregisterDeactivationHandlers_();

Expand Down
21 changes: 21 additions & 0 deletions test/unit/mdc-ripple/foundation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ testFoundation(`#destroy removes ${cssClasses.UNBOUNDED}`, ({foundation, adapter
td.verify(adapter.removeClass(cssClasses.UNBOUNDED));
});

testFoundation(`#destroy removes ${cssClasses.FG_ACTIVATION} if activation is interrupted`,
({foundation, adapter, mockRaf}) => {
foundation.activationTimer_ = 1;
foundation.destroy();
mockRaf.flush();

td.verify(adapter.removeClass(cssClasses.FG_ACTIVATION));
});

testFoundation('#destroy removes all CSS variables', ({foundation, adapter, mockRaf}) => {
const cssVars = Object.keys(strings).filter((s) => s.indexOf('VAR_') === 0).map((s) => strings[s]);
foundation.destroy();
Expand All @@ -176,6 +185,18 @@ testFoundation('#destroy removes all CSS variables', ({foundation, adapter, mock
});
});

testFoundation('#destroy clears the timer if activation is interrupted',
({foundation, mockRaf}) => {
foundation.init();
mockRaf.flush();

foundation.activationTimer_ = 1;
foundation.destroy();
mockRaf.flush();

assert.equal(foundation.activationTimer_, 0);
});

testFoundation('#destroy does nothing if CSS custom properties are not supported', ({foundation, adapter, mockRaf}) => {
const isA = td.matchers.isA;
td.when(adapter.browserSupportsCssVars()).thenReturn(false);
Expand Down

0 comments on commit 18cba98

Please sign in to comment.