diff --git a/src/lib/button/button.spec.ts b/src/lib/button/button.spec.ts index 3aed8f7fafac..26d9d6281710 100644 --- a/src/lib/button/button.spec.ts +++ b/src/lib/button/button.spec.ts @@ -3,7 +3,7 @@ import {Component, DebugElement} from '@angular/core'; import {By} from '@angular/platform-browser'; import {ViewportRuler} from '@angular/cdk/scrolling'; import {FakeViewportRuler} from '@angular/cdk/testing'; -import {MatButtonModule} from './index'; +import {MatButtonModule, MatButton} from './index'; import {MatRipple} from '@angular/material/core'; @@ -46,6 +46,13 @@ describe('MatButton', () => { expect(aDebugElement.nativeElement.classList).not.toContain('mat-accent'); }); + it('should expose the ripple instance', () => { + const fixture = TestBed.createComponent(TestApp); + const button = fixture.debugElement.query(By.css('button')).componentInstance as MatButton; + + expect(button.ripple).toBeTruthy(); + }); + it('should should not clear previous defined classes', () => { let fixture = TestBed.createComponent(TestApp); let testComponent = fixture.debugElement.componentInstance; diff --git a/src/lib/button/button.ts b/src/lib/button/button.ts index f4d29fc28b4d..6c350116cfa1 100644 --- a/src/lib/button/button.ts +++ b/src/lib/button/button.ts @@ -18,12 +18,14 @@ import { OnDestroy, Optional, Self, + ViewChild, ViewEncapsulation, } from '@angular/core'; import { CanColor, CanDisable, CanDisableRipple, + MatRipple, mixinColor, mixinDisabled, mixinDisableRipple @@ -135,6 +137,9 @@ export class MatButton extends _MatButtonMixinBase /** Whether the button is icon button. */ _isIconButton: boolean = this._hasHostAttributes('mat-icon-button'); + /** Reference to the MatRipple instance of the button. */ + @ViewChild(MatRipple) ripple: MatRipple; + constructor(elementRef: ElementRef, private _platform: Platform, private _focusMonitor: FocusMonitor) {