Skip to content

Commit e4789c7

Browse files
devversionkara
authored andcommitted
feat(tabs): allow disabling ripples (#4466)
1 parent ce74501 commit e4789c7

File tree

6 files changed

+97
-5
lines changed

6 files changed

+97
-5
lines changed

src/lib/tabs/tab-group.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<md-tab-header [selectedIndex]="selectedIndex" #tabHeader
1+
<md-tab-header #tabHeader
2+
[selectedIndex]="selectedIndex"
3+
[disableRipple]="disableRipple"
24
(indexFocused)="_focusChanged($event)"
35
(selectFocusedIndex)="selectedIndex = $event">
46
<div class="mat-tab-label" role="tab" md-tab-label-wrapper md-ripple
@@ -9,6 +11,7 @@
911
[attr.aria-selected]="selectedIndex == i"
1012
[class.mat-tab-label-active]="selectedIndex == i"
1113
[disabled]="tab.disabled"
14+
[mdRippleDisabled]="disableRipple"
1215
(click)="tabHeader.focusIndex = selectedIndex = i">
1316

1417
<!-- If there is a label template, use it. -->

src/lib/tabs/tab-group.spec.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {Observable} from 'rxjs/Observable';
99
import {MdTab} from './tab';
1010
import {ViewportRuler} from '../core/overlay/position/viewport-ruler';
1111
import {FakeViewportRuler} from '../core/overlay/position/fake-viewport-ruler';
12+
import {dispatchFakeEvent} from '../core/testing/dispatch-events';
1213

1314

1415
describe('MdTabGroup', () => {
@@ -139,6 +140,39 @@ describe('MdTabGroup', () => {
139140
fixture.detectChanges();
140141
}).not.toThrow();
141142
});
143+
144+
it('should show ripples for tab-group labels', () => {
145+
fixture.detectChanges();
146+
147+
const testElement = fixture.nativeElement;
148+
const tabLabel = fixture.debugElement.queryAll(By.css('.mat-tab-label'))[1];
149+
150+
expect(testElement.querySelectorAll('.mat-ripple-element').length)
151+
.toBe(0, 'Expected no ripples to show up initially.');
152+
153+
dispatchFakeEvent(tabLabel.nativeElement, 'mousedown');
154+
dispatchFakeEvent(tabLabel.nativeElement, 'mouseup');
155+
156+
expect(testElement.querySelectorAll('.mat-ripple-element').length)
157+
.toBe(1, 'Expected one ripple to show up on label mousedown.');
158+
});
159+
160+
it('should allow disabling ripples for tab-group labels', () => {
161+
fixture.componentInstance.disableRipple = true;
162+
fixture.detectChanges();
163+
164+
const testElement = fixture.nativeElement;
165+
const tabLabel = fixture.debugElement.queryAll(By.css('.mat-tab-label'))[1];
166+
167+
expect(testElement.querySelectorAll('.mat-ripple-element').length)
168+
.toBe(0, 'Expected no ripples to show up initially.');
169+
170+
dispatchFakeEvent(tabLabel.nativeElement, 'mousedown');
171+
dispatchFakeEvent(tabLabel.nativeElement, 'mouseup');
172+
173+
expect(testElement.querySelectorAll('.mat-ripple-element').length)
174+
.toBe(0, 'Expected no ripple to show up on label mousedown.');
175+
});
142176
});
143177

144178
describe('dynamic binding tabs', () => {
@@ -315,6 +349,7 @@ describe('nested MdTabGroup with enabled animations', () => {
315349
<md-tab-group class="tab-group"
316350
[(selectedIndex)]="selectedIndex"
317351
[headerPosition]="headerPosition"
352+
[disableRipple]="disableRipple"
318353
(focusChange)="handleFocus($event)"
319354
(selectChange)="handleSelection($event)">
320355
<md-tab>
@@ -336,6 +371,7 @@ class SimpleTabsTestApp {
336371
selectedIndex: number = 1;
337372
focusEvent: any;
338373
selectEvent: any;
374+
disableRipple: boolean = false;
339375
headerPosition: MdTabHeaderPosition = 'above';
340376
handleFocus(event: any) {
341377
this.focusEvent = event;

src/lib/tabs/tab-group.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ export class MdTabGroup {
6868
get _dynamicHeightDeprecated(): boolean { return this._dynamicHeight; }
6969
set _dynamicHeightDeprecated(value: boolean) { this._dynamicHeight = value; }
7070

71+
/** Whether ripples for the tab-group should be disabled or not. */
72+
@Input()
73+
get disableRipple(): boolean { return this._disableRipple; }
74+
set disableRipple(value) { this._disableRipple = coerceBooleanProperty(value); }
75+
private _disableRipple: boolean = false;
76+
77+
7178
private _selectedIndex: number = null;
7279

7380
/** The index of the active tab. */

src/lib/tabs/tab-header.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="mat-tab-header-pagination mat-tab-header-pagination-before mat-elevation-z4"
22
aria-hidden="true"
3-
md-ripple [mdRippleDisabled]="_disableScrollBefore"
3+
md-ripple [mdRippleDisabled]="_disableScrollBefore || disableRipple"
44
[class.mat-tab-header-pagination-disabled]="_disableScrollBefore"
55
(click)="_scrollHeader('before')">
66
<div class="mat-tab-header-pagination-chevron"></div>
@@ -18,7 +18,7 @@
1818

1919
<div class="mat-tab-header-pagination mat-tab-header-pagination-after mat-elevation-z4"
2020
aria-hidden="true"
21-
md-ripple [mdRippleDisabled]="_disableScrollAfter"
21+
md-ripple [mdRippleDisabled]="_disableScrollAfter || disableRipple"
2222
[class.mat-tab-header-pagination-disabled]="_disableScrollAfter"
2323
(click)="_scrollHeader('after')">
2424
<div class="mat-tab-header-pagination-chevron"></div>

src/lib/tabs/tab-header.spec.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {ViewportRuler} from '../core/overlay/position/viewport-ruler';
1313
import {dispatchKeyboardEvent} from '../core/testing/dispatch-events';
1414
import {dispatchFakeEvent} from '../core/testing/dispatch-events';
1515
import {Subject} from 'rxjs/Subject';
16+
import {By} from '@angular/platform-browser';
1617

1718

1819
describe('MdTabHeader', () => {
@@ -168,6 +169,44 @@ describe('MdTabHeader', () => {
168169
fixture.detectChanges();
169170
expect(appComponent.mdTabHeader.scrollDistance).toBe(0);
170171
});
172+
173+
it('should show ripples for pagination buttons', () => {
174+
appComponent.addTabsForScrolling();
175+
fixture.detectChanges();
176+
177+
expect(appComponent.mdTabHeader._showPaginationControls).toBe(true);
178+
179+
const buttonAfter = fixture.debugElement.query(By.css('.mat-tab-header-pagination-after'));
180+
181+
expect(fixture.nativeElement.querySelectorAll('.mat-ripple-element').length)
182+
.toBe(0, 'Expected no ripple to show up initially.');
183+
184+
dispatchFakeEvent(buttonAfter.nativeElement, 'mousedown');
185+
dispatchFakeEvent(buttonAfter.nativeElement, 'mouseup');
186+
187+
expect(fixture.nativeElement.querySelectorAll('.mat-ripple-element').length)
188+
.toBe(1, 'Expected one ripple to show up after mousedown');
189+
});
190+
191+
it('should allow disabling ripples for pagination buttons', () => {
192+
appComponent.addTabsForScrolling();
193+
appComponent.disableRipple = true;
194+
fixture.detectChanges();
195+
196+
expect(appComponent.mdTabHeader._showPaginationControls).toBe(true);
197+
198+
const buttonAfter = fixture.debugElement.query(By.css('.mat-tab-header-pagination-after'));
199+
200+
expect(fixture.nativeElement.querySelectorAll('.mat-ripple-element').length)
201+
.toBe(0, 'Expected no ripple to show up initially.');
202+
203+
dispatchFakeEvent(buttonAfter.nativeElement, 'mousedown');
204+
dispatchFakeEvent(buttonAfter.nativeElement, 'mouseup');
205+
206+
expect(fixture.nativeElement.querySelectorAll('.mat-ripple-element').length)
207+
.toBe(0, 'Expected no ripple to show up after mousedown');
208+
});
209+
171210
});
172211

173212
describe('rtl', () => {
@@ -238,7 +277,7 @@ interface Tab {
238277
@Component({
239278
template: `
240279
<div [dir]="dir">
241-
<md-tab-header [selectedIndex]="selectedIndex"
280+
<md-tab-header [selectedIndex]="selectedIndex" [disableRipple]="disableRipple"
242281
(indexFocused)="focusedIndex = $event"
243282
(selectFocusedIndex)="selectedIndex = $event">
244283
<div md-tab-label-wrapper style="min-width: 30px; width: 30px"
@@ -257,6 +296,7 @@ interface Tab {
257296
`]
258297
})
259298
class SimpleTabHeaderApp {
299+
disableRipple: boolean = false;
260300
selectedIndex: number = 0;
261301
focusedIndex: number;
262302
disabledTabIndex = 1;

src/lib/tabs/tab-header.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
OnDestroy,
1515
NgZone,
1616
} from '@angular/core';
17-
import {RIGHT_ARROW, LEFT_ARROW, ENTER, Dir, LayoutDirection} from '../core';
17+
import {RIGHT_ARROW, LEFT_ARROW, ENTER, Dir, LayoutDirection, coerceBooleanProperty} from '../core';
1818
import {MdTabLabelWrapper} from './tab-label-wrapper';
1919
import {MdInkBar} from './ink-bar';
2020
import {Subscription} from 'rxjs/Subscription';
@@ -108,6 +108,12 @@ export class MdTabHeader implements AfterContentChecked, AfterContentInit, OnDes
108108
this._focusIndex = value;
109109
}
110110

111+
/** Whether ripples for the tab-header labels should be disabled or not. */
112+
@Input()
113+
get disableRipple(): boolean { return this._disableRipple; }
114+
set disableRipple(value) { this._disableRipple = coerceBooleanProperty(value); }
115+
private _disableRipple: boolean = false;
116+
111117
/** Event emitted when the option is selected. */
112118
@Output() selectFocusedIndex = new EventEmitter();
113119

0 commit comments

Comments
 (0)