Skip to content

Commit 17e36fe

Browse files
devversionjelbourn
authored andcommitted
feat(button): expose ripple instance (#9170)
Exposes the `MatRipple` instance of the button as a public property. This can be used to show ripple indicators for feature discoveries as seen on the Specs (https://material.io/guidelines/growth-communications/feature-discovery.html#feature-discovery-design-patterns). Quote from the specs "Ripples guide users through subsequent steps". Closes #4179
1 parent 8a3e023 commit 17e36fe

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/lib/button/button.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
22
import {Component, DebugElement} from '@angular/core';
33
import {By} from '@angular/platform-browser';
4-
import {MatButtonModule} from './index';
4+
import {MatButtonModule, MatButton} from './index';
55
import {MatRipple} from '@angular/material/core';
66

77

@@ -41,6 +41,13 @@ describe('MatButton', () => {
4141
expect(aDebugElement.nativeElement.classList).not.toContain('mat-accent');
4242
});
4343

44+
it('should expose the ripple instance', () => {
45+
const fixture = TestBed.createComponent(TestApp);
46+
const button = fixture.debugElement.query(By.css('button')).componentInstance as MatButton;
47+
48+
expect(button.ripple).toBeTruthy();
49+
});
50+
4451
it('should should not clear previous defined classes', () => {
4552
let fixture = TestBed.createComponent(TestApp);
4653
let testComponent = fixture.debugElement.componentInstance;

src/lib/button/button.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ import {
1414
Directive,
1515
ElementRef,
1616
OnDestroy,
17+
ViewChild,
1718
ViewEncapsulation,
1819
} from '@angular/core';
1920
import {
2021
CanColor,
2122
CanDisable,
2223
CanDisableRipple,
24+
MatRipple,
2325
mixinColor,
2426
mixinDisabled,
2527
mixinDisableRipple
@@ -118,6 +120,9 @@ export class MatButton extends _MatButtonMixinBase
118120
/** Whether the button is icon button. */
119121
_isIconButton: boolean = this._hasHostAttributes('mat-icon-button');
120122

123+
/** Reference to the MatRipple instance of the button. */
124+
@ViewChild(MatRipple) ripple: MatRipple;
125+
121126
constructor(elementRef: ElementRef,
122127
private _platform: Platform,
123128
private _focusMonitor: FocusMonitor) {

0 commit comments

Comments
 (0)