Skip to content

fix(tabs): tab-nav-link disableRipple input not working #10643

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions src/lib/tabs/tab-nav-bar/tab-nav-bar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,29 @@ describe('MatTabNavBar', () => {
.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(MatTabLink))
.map(tabLinkDebug => tabLinkDebug.componentInstance) as MatTabLink[];

expect(tabLinkElements.every(tabLink => !tabLink.disableRipple))
it('should disable the ripples on all tabs when they are disabled on the nav bar', () => {
expect(fixture.componentInstance.tabLinks.toArray().every(tabLink => !tabLink.rippleDisabled))
.toBe(true, 'Expected every tab link to have ripples enabled');

fixture.componentInstance.disableRipple = true;
fixture.componentInstance.disableRippleOnBar = true;
fixture.detectChanges();

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

it('should have the `disableRipple` from the tab take precendence over the nav bar', () => {
const firstTab = fixture.componentInstance.tabLinks.first;

expect(firstTab.rippleDisabled).toBe(false, 'Expected ripples to be enabled on first tab');

firstTab.disableRipple = true;
fixture.componentInstance.disableRippleOnBar = false;
fixture.detectChanges();

expect(firstTab.rippleDisabled).toBe(true, 'Expected ripples to be disabled on first tab');
});

it('should update the tabindex if links are disabled', () => {
const tabLinkElements = fixture.debugElement.queryAll(By.css('a'))
.map(tabLinkDebugEl => tabLinkDebugEl.nativeElement);
Expand Down Expand Up @@ -219,7 +228,7 @@ describe('MatTabNavBar', () => {

spyOn(inkBar, 'hide');

fixture.componentInstance.links.forEach(link => link.active = false);
fixture.componentInstance.tabLinks.forEach(link => link.active = false);
fixture.detectChanges();

expect(inkBar.hide).toHaveBeenCalled();
Expand Down Expand Up @@ -269,7 +278,7 @@ describe('MatTabNavBar', () => {
@Component({
selector: 'test-app',
template: `
<nav mat-tab-nav-bar [disableRipple]="disableRipple">
<nav mat-tab-nav-bar [disableRipple]="disableRippleOnBar">
<a mat-tab-link
*ngFor="let tab of tabs; let index = index"
[active]="activeIndex === index"
Expand All @@ -282,11 +291,11 @@ describe('MatTabNavBar', () => {
})
class SimpleTabNavBarTestApp {
@ViewChild(MatTabNav) tabNavBar: MatTabNav;
@ViewChildren(MatTabLink) links: QueryList<MatTabLink>;
@ViewChildren(MatTabLink) tabLinks: QueryList<MatTabLink>;

label = '';
disabled: boolean = false;
disableRipple: boolean = false;
disabled = false;
disableRippleOnBar = false;
tabs = [0, 1, 2];

activeIndex = 0;
Expand Down
27 changes: 4 additions & 23 deletions src/lib/tabs/tab-nav-bar/tab-nav-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Directionality} from '@angular/cdk/bidi';
import {coerceBooleanProperty} from '@angular/cdk/coercion';
import {Platform} from '@angular/cdk/platform';
import {ViewportRuler} from '@angular/cdk/scrolling';
import {
Expand Down Expand Up @@ -53,7 +52,7 @@ import {MatInkBar} from '../ink-bar';
export class MatTabNavBase {
constructor(public _elementRef: ElementRef) {}
}
export const _MatTabNavMixinBase = mixinColor(MatTabNavBase, 'primary');
export const _MatTabNavMixinBase = mixinDisableRipple(mixinColor(MatTabNavBase, 'primary'));

/**
* Navigation component matching the styles of the tab group header.
Expand All @@ -63,15 +62,15 @@ export const _MatTabNavMixinBase = mixinColor(MatTabNavBase, 'primary');
moduleId: module.id,
selector: '[mat-tab-nav-bar]',
exportAs: 'matTabNavBar, matTabNav',
inputs: ['color'],
inputs: ['color', 'disableRipple'],
templateUrl: 'tab-nav-bar.html',
styleUrls: ['tab-nav-bar.css'],
host: {'class': 'mat-tab-nav-bar'},
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MatTabNav extends _MatTabNavMixinBase implements AfterContentInit, CanColor,
OnDestroy {
CanDisableRipple, OnDestroy {

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

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

constructor(elementRef: ElementRef,
@Optional() private _dir: Directionality,
private _ngZone: NgZone,
Expand All @@ -136,8 +126,6 @@ export class MatTabNav extends _MatTabNavMixinBase implements AfterContentInit,
.pipe(takeUntil(this._onDestroy))
.subscribe(() => this._alignInkBar());
});

this._setLinkDisableRipple();
}

/** Checks if the active link has been changed and, if so, will update the ink bar. */
Expand Down Expand Up @@ -165,13 +153,6 @@ export class MatTabNav extends _MatTabNavMixinBase implements AfterContentInit,
this._inkBar.hide();
}
}

/** Sets the `disableRipple` property on each link of the navigation bar. */
private _setLinkDisableRipple() {
if (this._tabLinks) {
this._tabLinks.forEach(link => link.disableRipple = this.disableRipple);
}
}
}


Expand Down Expand Up @@ -226,7 +207,7 @@ export class MatTabLink extends _MatTabLinkMixinBase
* @docs-private
*/
get rippleDisabled(): boolean {
return this.disabled || this.disableRipple;
return this.disabled || this.disableRipple || this._tabNavBar.disableRipple;
}

constructor(private _tabNavBar: MatTabNav,
Expand Down