Skip to content

Commit c4712e5

Browse files
committed
fix(tabs): tab-nav-link disableRipple input not working
* Fixes the `disableRipple` input on the `mat-tab-link` not working due to it being overwritten by the one from the `mat-tab-nav-bar`. * Switches the nav bar to use the mixin for disabling the ripple and simplifies the ripple disabling logic. Fixes #10636.
1 parent 7857b92 commit c4712e5

File tree

2 files changed

+25
-34
lines changed

2 files changed

+25
-34
lines changed

src/lib/tabs/tab-nav-bar/tab-nav-bar.spec.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {async, ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
2-
import {Component, ViewChild} from '@angular/core';
2+
import {Component, ViewChild, ViewChildren, QueryList} from '@angular/core';
33
import {By} from '@angular/platform-browser';
44
import {dispatchFakeEvent, dispatchMouseEvent, createMouseEvent} from '@angular/cdk/testing';
55
import {Direction, Directionality} from '@angular/cdk/bidi';
@@ -97,20 +97,29 @@ describe('MatTabNavBar', () => {
9797
.toBe(true, 'Expected aria-disabled to be set to "true" if link is disabled.');
9898
});
9999

100-
it('should update the disableRipple property on each tab link', () => {
101-
const tabLinkElements = fixture.debugElement.queryAll(By.directive(MatTabLink))
102-
.map(tabLinkDebug => tabLinkDebug.componentInstance) as MatTabLink[];
103-
104-
expect(tabLinkElements.every(tabLink => !tabLink.disableRipple))
100+
it('should disable the ripples on all tabs when they are disabled on the nav bar', () => {
101+
expect(fixture.componentInstance.tabLinks.toArray().every(tabLink => !tabLink.rippleDisabled))
105102
.toBe(true, 'Expected every tab link to have ripples enabled');
106103

107-
fixture.componentInstance.disableRipple = true;
104+
fixture.componentInstance.disableRippleOnBar = true;
108105
fixture.detectChanges();
109106

110-
expect(tabLinkElements.every(tabLink => tabLink.disableRipple))
107+
expect(fixture.componentInstance.tabLinks.toArray().every(tabLink => tabLink.rippleDisabled))
111108
.toBe(true, 'Expected every tab link to have ripples disabled');
112109
});
113110

111+
it('should have the `disableRipple` from the tab take precendence over the nav bar', () => {
112+
const firstTab = fixture.componentInstance.tabLinks.first;
113+
114+
expect(firstTab.rippleDisabled).toBe(false, 'Expected ripples to be enabled on first tab');
115+
116+
firstTab.disableRipple = true;
117+
fixture.componentInstance.disableRippleOnBar = false;
118+
fixture.detectChanges();
119+
120+
expect(firstTab.rippleDisabled).toBe(true, 'Expected ripples to be disabled on first tab');
121+
});
122+
114123
it('should update the tabindex if links are disabled', () => {
115124
const tabLinkElements = fixture.debugElement.queryAll(By.css('a'))
116125
.map(tabLinkDebugEl => tabLinkDebugEl.nativeElement);
@@ -258,7 +267,7 @@ describe('MatTabNavBar', () => {
258267
@Component({
259268
selector: 'test-app',
260269
template: `
261-
<nav mat-tab-nav-bar [disableRipple]="disableRipple">
270+
<nav mat-tab-nav-bar [disableRipple]="disableRippleOnBar">
262271
<a mat-tab-link
263272
*ngFor="let tab of tabs; let index = index"
264273
[active]="activeIndex === index"
@@ -271,10 +280,11 @@ describe('MatTabNavBar', () => {
271280
})
272281
class SimpleTabNavBarTestApp {
273282
@ViewChild(MatTabNav) tabNavBar: MatTabNav;
283+
@ViewChildren(MatTabLink) tabLinks: QueryList<MatTabLink>;
274284

275285
label = '';
276-
disabled: boolean = false;
277-
disableRipple: boolean = false;
286+
disabled = false;
287+
disableRippleOnBar = false;
278288
tabs = [0, 1, 2];
279289

280290
activeIndex = 0;

src/lib/tabs/tab-nav-bar/tab-nav-bar.ts

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import {Directionality} from '@angular/cdk/bidi';
9-
import {coerceBooleanProperty} from '@angular/cdk/coercion';
109
import {Platform} from '@angular/cdk/platform';
1110
import {ViewportRuler} from '@angular/cdk/scrolling';
1211
import {
@@ -55,7 +54,7 @@ import {MatInkBar} from '../ink-bar';
5554
export class MatTabNavBase {
5655
constructor(public _elementRef: ElementRef) {}
5756
}
58-
export const _MatTabNavMixinBase = mixinColor(MatTabNavBase, 'primary');
57+
export const _MatTabNavMixinBase = mixinDisableRipple(mixinColor(MatTabNavBase, 'primary'));
5958

6059
/**
6160
* Navigation component matching the styles of the tab group header.
@@ -65,15 +64,15 @@ export const _MatTabNavMixinBase = mixinColor(MatTabNavBase, 'primary');
6564
moduleId: module.id,
6665
selector: '[mat-tab-nav-bar]',
6766
exportAs: 'matTabNavBar, matTabNav',
68-
inputs: ['color'],
67+
inputs: ['color', 'disableRipple'],
6968
templateUrl: 'tab-nav-bar.html',
7069
styleUrls: ['tab-nav-bar.css'],
7170
host: {'class': 'mat-tab-nav-bar'},
7271
encapsulation: ViewEncapsulation.None,
7372
changeDetection: ChangeDetectionStrategy.OnPush,
7473
})
7574
export class MatTabNav extends _MatTabNavMixinBase implements AfterContentInit, CanColor,
76-
OnDestroy {
75+
CanDisableRipple, OnDestroy {
7776

7877
/** Subject that emits when the component has been destroyed. */
7978
private readonly _onDestroy = new Subject<void>();
@@ -103,15 +102,6 @@ export class MatTabNav extends _MatTabNavMixinBase implements AfterContentInit,
103102
}
104103
private _backgroundColor: ThemePalette;
105104

106-
/** Whether ripples should be disabled for all links or not. */
107-
@Input()
108-
get disableRipple() { return this._disableRipple; }
109-
set disableRipple(value: boolean) {
110-
this._disableRipple = coerceBooleanProperty(value);
111-
this._setLinkDisableRipple();
112-
}
113-
private _disableRipple: boolean = false;
114-
115105
constructor(elementRef: ElementRef,
116106
@Optional() private _dir: Directionality,
117107
private _ngZone: NgZone,
@@ -137,8 +127,6 @@ export class MatTabNav extends _MatTabNavMixinBase implements AfterContentInit,
137127
return merge(dirChange, this._viewportRuler.change(10)).pipe(takeUntil(this._onDestroy))
138128
.subscribe(() => this._alignInkBar());
139129
});
140-
141-
this._setLinkDisableRipple();
142130
}
143131

144132
/** Checks if the active link has been changed and, if so, will update the ink bar. */
@@ -160,13 +148,6 @@ export class MatTabNav extends _MatTabNavMixinBase implements AfterContentInit,
160148
this._inkBar.alignToElement(this._activeLinkElement.nativeElement);
161149
}
162150
}
163-
164-
/** Sets the `disableRipple` property on each link of the navigation bar. */
165-
private _setLinkDisableRipple() {
166-
if (this._tabLinks) {
167-
this._tabLinks.forEach(link => link.disableRipple = this.disableRipple);
168-
}
169-
}
170151
}
171152

172153

@@ -221,7 +202,7 @@ export class MatTabLink extends _MatTabLinkMixinBase
221202
* @docs-private
222203
*/
223204
get rippleDisabled(): boolean {
224-
return this.disabled || this.disableRipple;
205+
return this.disabled || this.disableRipple || this._tabNavBar.disableRipple;
225206
}
226207

227208
constructor(private _tabNavBar: MatTabNav,

0 commit comments

Comments
 (0)