From 4ae1b0f372e0d46d167ea5db2b6136657272ca92 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Tue, 8 Aug 2017 22:24:49 +0200 Subject: [PATCH] feat(tab-nav-bar): allow disabling ripples for links (#6273) * Adds a possibility to disable ripples for a tab-nav-bar with links. Closes #6245 --- src/lib/core/ripple/ripple.ts | 2 +- src/lib/tabs/tab-nav-bar/tab-nav-bar.spec.ts | 33 ++++++++++++++- src/lib/tabs/tab-nav-bar/tab-nav-bar.ts | 44 ++++++++++++++++++-- 3 files changed, 73 insertions(+), 6 deletions(-) diff --git a/src/lib/core/ripple/ripple.ts b/src/lib/core/ripple/ripple.ts index dd2d627895e5..5f25f10fce80 100644 --- a/src/lib/core/ripple/ripple.ts +++ b/src/lib/core/ripple/ripple.ts @@ -135,7 +135,7 @@ export class MdRipple implements OnChanges, OnDestroy { } /** Updates the ripple renderer with the latest ripple configuration. */ - private _updateRippleRenderer() { + _updateRippleRenderer() { this._rippleRenderer.rippleDisabled = this._globalOptions.disabled || this.disabled; this._rippleRenderer.rippleConfig = this.rippleConfig; } diff --git a/src/lib/tabs/tab-nav-bar/tab-nav-bar.spec.ts b/src/lib/tabs/tab-nav-bar/tab-nav-bar.spec.ts index 92427a06c58e..7b6abc8abbb3 100644 --- a/src/lib/tabs/tab-nav-bar/tab-nav-bar.spec.ts +++ b/src/lib/tabs/tab-nav-bar/tab-nav-bar.spec.ts @@ -1,6 +1,6 @@ import {async, ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing'; import {MdTabsModule} from '../index'; -import {MdTabNav} from './tab-nav-bar'; +import {MdTabNav, MdTabLink} from './tab-nav-bar'; import {Component, ViewChild} from '@angular/core'; import {By} from '@angular/platform-browser'; import {ViewportRuler} from '../../core/overlay/position/viewport-ruler'; @@ -81,6 +81,20 @@ describe('MdTabNavBar', () => { .toBe(true, 'Expected aria-disabled to be set to "true" if link is disabled.'); }); + it('should update the disableRipple property on each tab link', () => { + const tabLinkElements = fixture.debugElement.queryAll(By.directive(MdTabLink)) + .map(tabLinkDebug => tabLinkDebug.componentInstance) as MdTabLink[]; + + expect(tabLinkElements.every(tabLink => !tabLink.disableRipple)) + .toBe(true, 'Expected every tab link to have ripples enabled'); + + fixture.componentInstance.disableRipple = true; + fixture.detectChanges(); + + expect(tabLinkElements.every(tabLink => tabLink.disableRipple)) + .toBe(true, 'Expected every tab link to have ripples disabled'); + }); + it('should update the tabindex if links are disabled', () => { const tabLinkElements = fixture.debugElement.queryAll(By.css('a')) .map(tabLinkDebugEl => tabLinkDebugEl.nativeElement); @@ -105,6 +119,20 @@ describe('MdTabNavBar', () => { .toBe(1, 'Expected one ripple to show up if user clicks on tab link.'); }); + it('should be able to disable ripples on a tab link', () => { + const tabLinkDebug = fixture.debugElement.query(By.css('a')); + const tabLinkElement = tabLinkDebug.nativeElement; + const tabLinkInstance = tabLinkDebug.injector.get(MdTabLink); + + tabLinkInstance.disableRipple = true; + + dispatchMouseEvent(tabLinkElement, 'mousedown'); + dispatchMouseEvent(tabLinkElement, 'mouseup'); + + expect(tabLinkElement.querySelectorAll('.mat-ripple-element').length) + .toBe(0, 'Expected no ripple to show up if ripples are disabled.'); + }); + it('should re-align the ink bar when the direction changes', () => { const inkBar = fixture.componentInstance.tabNavBar._inkBar; @@ -173,7 +201,7 @@ describe('MdTabNavBar', () => { @Component({ selector: 'test-app', template: ` -