Skip to content

Commit 00e9338

Browse files
josephperrottkara
authored andcommitted
feat(nav-tabs): add mat-tab-label-active class to active nav tab labels (#7508)
1 parent 4a1a68d commit 00e9338

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
@@ -49,6 +49,24 @@ describe('MatTabNavBar', () => {
4949
expect(fixture.componentInstance.activeIndex).toBe(2);
5050
});
5151

52+
it('should add the active class if active', () => {
53+
let tabLink1 = fixture.debugElement.queryAll(By.css('a'))[0];
54+
let tabLink2 = fixture.debugElement.queryAll(By.css('a'))[1];
55+
const tabLinkElements = fixture.debugElement.queryAll(By.css('a'))
56+
.map(tabLinkDebugEl => tabLinkDebugEl.nativeElement);
57+
58+
tabLink1.nativeElement.click();
59+
fixture.detectChanges();
60+
expect(tabLinkElements[0].classList.contains('mat-tab-label-active')).toBeTruthy();
61+
expect(tabLinkElements[1].classList.contains('mat-tab-label-active')).toBeFalsy();
62+
63+
tabLink2.nativeElement.click();
64+
fixture.detectChanges();
65+
expect(tabLinkElements[0].classList.contains('mat-tab-label-active')).toBeFalsy();
66+
expect(tabLinkElements[1].classList.contains('mat-tab-label-active')).toBeTruthy();
67+
68+
});
69+
5270
it('should add the disabled class if disabled', () => {
5371
const tabLinkElements = fixture.debugElement.queryAll(By.css('a'))
5472
.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
@@ -184,7 +184,8 @@ export const _MatTabLinkMixinBase = mixinDisabled(MatTabLinkBase);
184184
'class': 'mat-tab-link',
185185
'[attr.aria-disabled]': 'disabled.toString()',
186186
'[attr.tabindex]': 'tabIndex',
187-
'[class.mat-tab-disabled]': 'disabled'
187+
'[class.mat-tab-disabled]': 'disabled',
188+
'[class.mat-tab-label-active]': 'active',
188189
}
189190
})
190191
export class MatTabLink extends _MatTabLinkMixinBase implements OnDestroy, CanDisable {

0 commit comments

Comments
 (0)