Skip to content

Commit

Permalink
feat(tabs): allow disabling ripples (#4466)
Browse files Browse the repository at this point in the history
  • Loading branch information
devversion authored and kara committed May 10, 2017
1 parent ce74501 commit e4789c7
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/lib/tabs/tab-group.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<md-tab-header [selectedIndex]="selectedIndex" #tabHeader
<md-tab-header #tabHeader
[selectedIndex]="selectedIndex"
[disableRipple]="disableRipple"
(indexFocused)="_focusChanged($event)"
(selectFocusedIndex)="selectedIndex = $event">
<div class="mat-tab-label" role="tab" md-tab-label-wrapper md-ripple
Expand All @@ -9,6 +11,7 @@
[attr.aria-selected]="selectedIndex == i"
[class.mat-tab-label-active]="selectedIndex == i"
[disabled]="tab.disabled"
[mdRippleDisabled]="disableRipple"
(click)="tabHeader.focusIndex = selectedIndex = i">

<!-- If there is a label template, use it. -->
Expand Down
36 changes: 36 additions & 0 deletions src/lib/tabs/tab-group.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {Observable} from 'rxjs/Observable';
import {MdTab} from './tab';
import {ViewportRuler} from '../core/overlay/position/viewport-ruler';
import {FakeViewportRuler} from '../core/overlay/position/fake-viewport-ruler';
import {dispatchFakeEvent} from '../core/testing/dispatch-events';


describe('MdTabGroup', () => {
Expand Down Expand Up @@ -139,6 +140,39 @@ describe('MdTabGroup', () => {
fixture.detectChanges();
}).not.toThrow();
});

it('should show ripples for tab-group labels', () => {
fixture.detectChanges();

const testElement = fixture.nativeElement;
const tabLabel = fixture.debugElement.queryAll(By.css('.mat-tab-label'))[1];

expect(testElement.querySelectorAll('.mat-ripple-element').length)
.toBe(0, 'Expected no ripples to show up initially.');

dispatchFakeEvent(tabLabel.nativeElement, 'mousedown');
dispatchFakeEvent(tabLabel.nativeElement, 'mouseup');

expect(testElement.querySelectorAll('.mat-ripple-element').length)
.toBe(1, 'Expected one ripple to show up on label mousedown.');
});

it('should allow disabling ripples for tab-group labels', () => {
fixture.componentInstance.disableRipple = true;
fixture.detectChanges();

const testElement = fixture.nativeElement;
const tabLabel = fixture.debugElement.queryAll(By.css('.mat-tab-label'))[1];

expect(testElement.querySelectorAll('.mat-ripple-element').length)
.toBe(0, 'Expected no ripples to show up initially.');

dispatchFakeEvent(tabLabel.nativeElement, 'mousedown');
dispatchFakeEvent(tabLabel.nativeElement, 'mouseup');

expect(testElement.querySelectorAll('.mat-ripple-element').length)
.toBe(0, 'Expected no ripple to show up on label mousedown.');
});
});

describe('dynamic binding tabs', () => {
Expand Down Expand Up @@ -315,6 +349,7 @@ describe('nested MdTabGroup with enabled animations', () => {
<md-tab-group class="tab-group"
[(selectedIndex)]="selectedIndex"
[headerPosition]="headerPosition"
[disableRipple]="disableRipple"
(focusChange)="handleFocus($event)"
(selectChange)="handleSelection($event)">
<md-tab>
Expand All @@ -336,6 +371,7 @@ class SimpleTabsTestApp {
selectedIndex: number = 1;
focusEvent: any;
selectEvent: any;
disableRipple: boolean = false;
headerPosition: MdTabHeaderPosition = 'above';
handleFocus(event: any) {
this.focusEvent = event;
Expand Down
7 changes: 7 additions & 0 deletions src/lib/tabs/tab-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ export class MdTabGroup {
get _dynamicHeightDeprecated(): boolean { return this._dynamicHeight; }
set _dynamicHeightDeprecated(value: boolean) { this._dynamicHeight = value; }

/** Whether ripples for the tab-group should be disabled or not. */
@Input()
get disableRipple(): boolean { return this._disableRipple; }
set disableRipple(value) { this._disableRipple = coerceBooleanProperty(value); }
private _disableRipple: boolean = false;


private _selectedIndex: number = null;

/** The index of the active tab. */
Expand Down
4 changes: 2 additions & 2 deletions src/lib/tabs/tab-header.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="mat-tab-header-pagination mat-tab-header-pagination-before mat-elevation-z4"
aria-hidden="true"
md-ripple [mdRippleDisabled]="_disableScrollBefore"
md-ripple [mdRippleDisabled]="_disableScrollBefore || disableRipple"
[class.mat-tab-header-pagination-disabled]="_disableScrollBefore"
(click)="_scrollHeader('before')">
<div class="mat-tab-header-pagination-chevron"></div>
Expand All @@ -18,7 +18,7 @@

<div class="mat-tab-header-pagination mat-tab-header-pagination-after mat-elevation-z4"
aria-hidden="true"
md-ripple [mdRippleDisabled]="_disableScrollAfter"
md-ripple [mdRippleDisabled]="_disableScrollAfter || disableRipple"
[class.mat-tab-header-pagination-disabled]="_disableScrollAfter"
(click)="_scrollHeader('after')">
<div class="mat-tab-header-pagination-chevron"></div>
Expand Down
42 changes: 41 additions & 1 deletion src/lib/tabs/tab-header.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {ViewportRuler} from '../core/overlay/position/viewport-ruler';
import {dispatchKeyboardEvent} from '../core/testing/dispatch-events';
import {dispatchFakeEvent} from '../core/testing/dispatch-events';
import {Subject} from 'rxjs/Subject';
import {By} from '@angular/platform-browser';


describe('MdTabHeader', () => {
Expand Down Expand Up @@ -168,6 +169,44 @@ describe('MdTabHeader', () => {
fixture.detectChanges();
expect(appComponent.mdTabHeader.scrollDistance).toBe(0);
});

it('should show ripples for pagination buttons', () => {
appComponent.addTabsForScrolling();
fixture.detectChanges();

expect(appComponent.mdTabHeader._showPaginationControls).toBe(true);

const buttonAfter = fixture.debugElement.query(By.css('.mat-tab-header-pagination-after'));

expect(fixture.nativeElement.querySelectorAll('.mat-ripple-element').length)
.toBe(0, 'Expected no ripple to show up initially.');

dispatchFakeEvent(buttonAfter.nativeElement, 'mousedown');
dispatchFakeEvent(buttonAfter.nativeElement, 'mouseup');

expect(fixture.nativeElement.querySelectorAll('.mat-ripple-element').length)
.toBe(1, 'Expected one ripple to show up after mousedown');
});

it('should allow disabling ripples for pagination buttons', () => {
appComponent.addTabsForScrolling();
appComponent.disableRipple = true;
fixture.detectChanges();

expect(appComponent.mdTabHeader._showPaginationControls).toBe(true);

const buttonAfter = fixture.debugElement.query(By.css('.mat-tab-header-pagination-after'));

expect(fixture.nativeElement.querySelectorAll('.mat-ripple-element').length)
.toBe(0, 'Expected no ripple to show up initially.');

dispatchFakeEvent(buttonAfter.nativeElement, 'mousedown');
dispatchFakeEvent(buttonAfter.nativeElement, 'mouseup');

expect(fixture.nativeElement.querySelectorAll('.mat-ripple-element').length)
.toBe(0, 'Expected no ripple to show up after mousedown');
});

});

describe('rtl', () => {
Expand Down Expand Up @@ -238,7 +277,7 @@ interface Tab {
@Component({
template: `
<div [dir]="dir">
<md-tab-header [selectedIndex]="selectedIndex"
<md-tab-header [selectedIndex]="selectedIndex" [disableRipple]="disableRipple"
(indexFocused)="focusedIndex = $event"
(selectFocusedIndex)="selectedIndex = $event">
<div md-tab-label-wrapper style="min-width: 30px; width: 30px"
Expand All @@ -257,6 +296,7 @@ interface Tab {
`]
})
class SimpleTabHeaderApp {
disableRipple: boolean = false;
selectedIndex: number = 0;
focusedIndex: number;
disabledTabIndex = 1;
Expand Down
8 changes: 7 additions & 1 deletion src/lib/tabs/tab-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
OnDestroy,
NgZone,
} from '@angular/core';
import {RIGHT_ARROW, LEFT_ARROW, ENTER, Dir, LayoutDirection} from '../core';
import {RIGHT_ARROW, LEFT_ARROW, ENTER, Dir, LayoutDirection, coerceBooleanProperty} from '../core';
import {MdTabLabelWrapper} from './tab-label-wrapper';
import {MdInkBar} from './ink-bar';
import {Subscription} from 'rxjs/Subscription';
Expand Down Expand Up @@ -108,6 +108,12 @@ export class MdTabHeader implements AfterContentChecked, AfterContentInit, OnDes
this._focusIndex = value;
}

/** Whether ripples for the tab-header labels should be disabled or not. */
@Input()
get disableRipple(): boolean { return this._disableRipple; }
set disableRipple(value) { this._disableRipple = coerceBooleanProperty(value); }
private _disableRipple: boolean = false;

/** Event emitted when the option is selected. */
@Output() selectFocusedIndex = new EventEmitter();

Expand Down

0 comments on commit e4789c7

Please sign in to comment.