Skip to content

Commit 45e1b29

Browse files
crisbetoandrewseguin
authored andcommitted
fix(tabs): tab-nav-link disableRipple input not working (#10643)
* 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 5c91e73 commit 45e1b29

File tree

2 files changed

+25
-35
lines changed

2 files changed

+25
-35
lines changed

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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);
@@ -219,7 +228,7 @@ describe('MatTabNavBar', () => {
219228

220229
spyOn(inkBar, 'hide');
221230

222-
fixture.componentInstance.links.forEach(link => link.active = false);
231+
fixture.componentInstance.tabLinks.forEach(link => link.active = false);
223232
fixture.detectChanges();
224233

225234
expect(inkBar.hide).toHaveBeenCalled();
@@ -269,7 +278,7 @@ describe('MatTabNavBar', () => {
269278
@Component({
270279
selector: 'test-app',
271280
template: `
272-
<nav mat-tab-nav-bar [disableRipple]="disableRipple">
281+
<nav mat-tab-nav-bar [disableRipple]="disableRippleOnBar">
273282
<a mat-tab-link
274283
*ngFor="let tab of tabs; let index = index"
275284
[active]="activeIndex === index"
@@ -282,11 +291,11 @@ describe('MatTabNavBar', () => {
282291
})
283292
class SimpleTabNavBarTestApp {
284293
@ViewChild(MatTabNav) tabNavBar: MatTabNav;
285-
@ViewChildren(MatTabLink) links: QueryList<MatTabLink>;
294+
@ViewChildren(MatTabLink) tabLinks: QueryList<MatTabLink>;
286295

287296
label = '';
288-
disabled: boolean = false;
289-
disableRipple: boolean = false;
297+
disabled = false;
298+
disableRippleOnBar = false;
290299
tabs = [0, 1, 2];
291300

292301
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 {
@@ -53,7 +52,7 @@ import {MatInkBar} from '../ink-bar';
5352
export class MatTabNavBase {
5453
constructor(public _elementRef: ElementRef) {}
5554
}
56-
export const _MatTabNavMixinBase = mixinColor(MatTabNavBase, 'primary');
55+
export const _MatTabNavMixinBase = mixinDisableRipple(mixinColor(MatTabNavBase, 'primary'));
5756

5857
/**
5958
* Navigation component matching the styles of the tab group header.
@@ -63,15 +62,15 @@ export const _MatTabNavMixinBase = mixinColor(MatTabNavBase, 'primary');
6362
moduleId: module.id,
6463
selector: '[mat-tab-nav-bar]',
6564
exportAs: 'matTabNavBar, matTabNav',
66-
inputs: ['color'],
65+
inputs: ['color', 'disableRipple'],
6766
templateUrl: 'tab-nav-bar.html',
6867
styleUrls: ['tab-nav-bar.css'],
6968
host: {'class': 'mat-tab-nav-bar'},
7069
encapsulation: ViewEncapsulation.None,
7170
changeDetection: ChangeDetectionStrategy.OnPush,
7271
})
7372
export class MatTabNav extends _MatTabNavMixinBase implements AfterContentInit, CanColor,
74-
OnDestroy {
73+
CanDisableRipple, OnDestroy {
7574

7675
/** Subject that emits when the component has been destroyed. */
7776
private readonly _onDestroy = new Subject<void>();
@@ -101,15 +100,6 @@ export class MatTabNav extends _MatTabNavMixinBase implements AfterContentInit,
101100
}
102101
private _backgroundColor: ThemePalette;
103102

104-
/** Whether ripples should be disabled for all links or not. */
105-
@Input()
106-
get disableRipple() { return this._disableRipple; }
107-
set disableRipple(value: boolean) {
108-
this._disableRipple = coerceBooleanProperty(value);
109-
this._setLinkDisableRipple();
110-
}
111-
private _disableRipple: boolean = false;
112-
113103
constructor(elementRef: ElementRef,
114104
@Optional() private _dir: Directionality,
115105
private _ngZone: NgZone,
@@ -137,8 +127,6 @@ export class MatTabNav extends _MatTabNavMixinBase implements AfterContentInit,
137127
.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. */
@@ -166,13 +154,6 @@ export class MatTabNav extends _MatTabNavMixinBase implements AfterContentInit,
166154
this._inkBar.hide();
167155
}
168156
}
169-
170-
/** Sets the `disableRipple` property on each link of the navigation bar. */
171-
private _setLinkDisableRipple() {
172-
if (this._tabLinks) {
173-
this._tabLinks.forEach(link => link.disableRipple = this.disableRipple);
174-
}
175-
}
176157
}
177158

178159

@@ -227,7 +208,7 @@ export class MatTabLink extends _MatTabLinkMixinBase
227208
* @docs-private
228209
*/
229210
get rippleDisabled(): boolean {
230-
return this.disabled || this.disableRipple;
211+
return this.disabled || this.disableRipple || this._tabNavBar.disableRipple;
231212
}
232213

233214
constructor(private _tabNavBar: MatTabNav,

0 commit comments

Comments
 (0)