Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ripple): global ripple configuration on init #4238

Merged
merged 1 commit into from
Apr 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/lib/core/ripple/ripple.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('MdRipple', () => {
declarations: [
BasicRippleContainer,
RippleContainerWithInputBindings,
RippleContainerWithoutBindings,
RippleContainerWithNgIf,
],
});
Expand Down Expand Up @@ -351,23 +352,38 @@ describe('MdRipple', () => {
describe('global ripple options', () => {
let rippleDirective: MdRipple;

function createTestComponent(rippleConfig: RippleGlobalOptions) {
function createTestComponent(rippleConfig: RippleGlobalOptions,
testComponent: any = BasicRippleContainer) {
// Reset the previously configured testing module to be able set new providers.
// The testing module has been initialized in the root describe group for the ripples.
TestBed.resetTestingModule();
TestBed.configureTestingModule({
imports: [MdRippleModule],
declarations: [BasicRippleContainer],
declarations: [testComponent],
providers: [{ provide: MD_RIPPLE_GLOBAL_OPTIONS, useValue: rippleConfig }]
});

fixture = TestBed.createComponent(BasicRippleContainer);
fixture = TestBed.createComponent(testComponent);
fixture.detectChanges();

rippleTarget = fixture.nativeElement.querySelector('[mat-ripple]');
rippleDirective = fixture.componentInstance.ripple;
}

it('should work without having any binding set', () => {
createTestComponent({ disabled: true }, RippleContainerWithoutBindings);

dispatchMouseEvent(rippleTarget, 'mousedown');
dispatchMouseEvent(rippleTarget, 'mouseup');

expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(0);

dispatchMouseEvent(rippleTarget, 'mousedown');
dispatchMouseEvent(rippleTarget, 'mouseup');

expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(0);
});

it('when disabled should not show any ripples on mousedown', () => {
createTestComponent({ disabled: true });

Expand Down Expand Up @@ -577,6 +593,11 @@ class RippleContainerWithInputBindings {
@ViewChild(MdRipple) ripple: MdRipple;
}

@Component({
template: `<div id="container" #ripple="mdRipple" mat-ripple></div>`,
})
class RippleContainerWithoutBindings {}

@Component({ template: `<div id="container" mat-ripple [mdRippleSpeedFactor]="0"
*ngIf="!isDestroyed"></div>` })
class RippleContainerWithNgIf {
Expand Down
11 changes: 9 additions & 2 deletions src/lib/core/ripple/ripple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,16 @@ export class MdRipple implements OnChanges, OnDestroy {
) {
this._rippleRenderer = new RippleRenderer(elementRef, ngZone, ruler);
this._globalOptions = globalOptions ? globalOptions : {};

this._updateRippleRenderer();
}

ngOnChanges(changes: SimpleChanges) {
if (changes['trigger'] && this.trigger) {
this._rippleRenderer.setTriggerElement(this.trigger);
}

this._rippleRenderer.rippleDisabled = this._globalOptions.disabled || this.disabled;
this._rippleRenderer.rippleConfig = this.rippleConfig;
this._updateRippleRenderer();
}

ngOnDestroy() {
Expand All @@ -122,4 +123,10 @@ export class MdRipple implements OnChanges, OnDestroy {
color: this.color
};
}

/** Updates the ripple renderer with the latest ripple configuration. */
private _updateRippleRenderer() {
this._rippleRenderer.rippleDisabled = this._globalOptions.disabled || this.disabled;
this._rippleRenderer.rippleConfig = this.rippleConfig;
}
}