Skip to content

Commit ec2c210

Browse files
committed
feat(button): expose ripple instance
* 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 c3d7cd9 commit ec2c210

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
@@ -3,7 +3,7 @@ import {Component, DebugElement} from '@angular/core';
33
import {By} from '@angular/platform-browser';
44
import {ViewportRuler} from '@angular/cdk/scrolling';
55
import {FakeViewportRuler} from '@angular/cdk/testing';
6-
import {MatButtonModule} from './index';
6+
import {MatButtonModule, MatButton} from './index';
77
import {MatRipple} from '@angular/material/core';
88

99

@@ -46,6 +46,13 @@ describe('MatButton', () => {
4646
expect(aDebugElement.nativeElement.classList).not.toContain('mat-accent');
4747
});
4848

49+
it('should expose the ripple instance', () => {
50+
const fixture = TestBed.createComponent(TestApp);
51+
const button = fixture.debugElement.query(By.css('button')).componentInstance as MatButton;
52+
53+
expect(button.ripple).toBeTruthy();
54+
});
55+
4956
it('should should not clear previous defined classes', () => {
5057
let fixture = TestBed.createComponent(TestApp);
5158
let testComponent = fixture.debugElement.componentInstance;

src/lib/button/button.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ import {
1818
OnDestroy,
1919
Optional,
2020
Self,
21+
ViewChild,
2122
ViewEncapsulation,
2223
} from '@angular/core';
2324
import {
2425
CanColor,
2526
CanDisable,
2627
CanDisableRipple,
28+
MatRipple,
2729
mixinColor,
2830
mixinDisabled,
2931
mixinDisableRipple
@@ -135,6 +137,9 @@ export class MatButton extends _MatButtonMixinBase
135137
/** Whether the button is icon button. */
136138
_isIconButton: boolean = this._hasHostAttributes('mat-icon-button');
137139

140+
/** Reference to the MatRipple instance of the button. */
141+
@ViewChild(MatRipple) ripple: MatRipple;
142+
138143
constructor(elementRef: ElementRef,
139144
private _platform: Platform,
140145
private _focusMonitor: FocusMonitor) {

0 commit comments

Comments
 (0)