Skip to content

Commit a1e33f6

Browse files
committed
add mat-tab-label-active class to active nav tab labels
1 parent ac70420 commit a1e33f6

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ describe('MatTabNavBar', () => {
5151
expect(fixture.componentInstance.activeIndex).toBe(2);
5252
});
5353

54+
it('should add the active class if active', () => {
55+
let tabLink1 = fixture.debugElement.queryAll(By.css('a'))[0];
56+
let tabLink2 = fixture.debugElement.queryAll(By.css('a'))[1];
57+
const tabLinkElements = fixture.debugElement.queryAll(By.css('a'))
58+
.map(tabLinkDebugEl => tabLinkDebugEl.nativeElement);
59+
60+
tabLink1.nativeElement.click();
61+
fixture.detectChanges();
62+
expect(tabLinkElements[0].classList.contains('mat-tab-label-active')).toBeTruthy();
63+
expect(tabLinkElements[1].classList.contains('mat-tab-label-active')).toBeFalsy();
64+
65+
tabLink2.nativeElement.click();
66+
fixture.detectChanges();
67+
expect(tabLinkElements[0].classList.contains('mat-tab-label-active')).toBeFalsy();
68+
expect(tabLinkElements[1].classList.contains('mat-tab-label-active')).toBeTruthy();
69+
70+
});
71+
5472
it('should add the disabled class if disabled', () => {
5573
const tabLinkElements = fixture.debugElement.queryAll(By.css('a'))
5674
.map(tabLinkDebugEl => tabLinkDebugEl.nativeElement);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ export const _MatTabLinkMixinBase = mixinDisabled(MatTabLinkBase);
186186
'class': 'mat-tab-link',
187187
'[attr.aria-disabled]': 'disabled.toString()',
188188
'[attr.tabindex]': 'tabIndex',
189-
'[class.mat-tab-disabled]': 'disabled'
189+
'[class.mat-tab-disabled]': 'disabled',
190+
'[class.mat-tab-label-active]': 'active',
190191
}
191192
})
192193
export class MatTabLink extends _MatTabLinkMixinBase implements OnDestroy, CanDisable {

0 commit comments

Comments
 (0)