Skip to content
This repository has been archived by the owner on Oct 7, 2020. It is now read-only.

Commit

Permalink
fix(ripple): Throws exception with Ivy (#2116)
Browse files Browse the repository at this point in the history
closes #2110
  • Loading branch information
trimox authored Feb 19, 2020
1 parent 18d3e37 commit 244e62c
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions packages/ripple/ripple.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {AfterViewInit, Directive, ElementRef, Input, OnDestroy} from '@angular/core';
import {AfterViewInit, Directive, ElementRef, Input, OnChanges, OnDestroy, SimpleChanges} from '@angular/core';
import {coerceBooleanProperty} from '@angular/cdk/coercion';
import {supportsPassiveEventListeners} from '@angular/cdk/platform';

Expand All @@ -10,7 +10,7 @@ import {MDCRippleFoundation, MDCRippleAdapter} from '@material/ripple';
selector: '[mdcRipple], mdc-ripple',
providers: [MdcRipple],
})
export class MdcRippleDirective implements AfterViewInit, OnDestroy, MDCRippleCapableSurface {
export class MdcRippleDirective implements AfterViewInit, OnChanges, OnDestroy, MDCRippleCapableSurface {
_root!: Element;

@Input()
Expand All @@ -29,11 +29,6 @@ export class MdcRippleDirective implements AfterViewInit, OnDestroy, MDCRippleCa
}
set primary(value: boolean) {
this._primary = coerceBooleanProperty(value);
if (this._primary) {
this.attachTo.classList.add('mdc-ripple-surface--primary');
} else {
this.attachTo.classList.remove('mdc-ripple-surface--primary');
}
}
private _primary = false;

Expand All @@ -43,11 +38,6 @@ export class MdcRippleDirective implements AfterViewInit, OnDestroy, MDCRippleCa
}
set secondary(value: boolean) {
this._secondary = coerceBooleanProperty(value);
if (this._secondary) {
this.attachTo.classList.add('mdc-ripple-surface--accent');
} else {
this.attachTo.classList.remove('mdc-ripple-surface--accent');
}
}
private _secondary = false;

Expand Down Expand Up @@ -76,6 +66,24 @@ export class MdcRippleDirective implements AfterViewInit, OnDestroy, MDCRippleCa
this._ripple = this._createRipple();
}

ngOnChanges(changes: SimpleChanges) {
if (changes['primary'] && this.attachTo) {
if (this._primary) {
this.attachTo.classList.add('mdc-ripple-surface--primary');
} else {
this.attachTo.classList.remove('mdc-ripple-surface--primary');
}
}

if (changes['secondary'] && this.attachTo) {
if (this._secondary) {
this.attachTo.classList.add('mdc-ripple-surface--accent');
} else {
this.attachTo.classList.remove('mdc-ripple-surface--accent');
}
}
}

ngAfterViewInit(): void {
this._ripple.init();
}
Expand Down

0 comments on commit 244e62c

Please sign in to comment.