Skip to content

Commit 83043a0

Browse files
committed
fix(tabs): update mat-tab-link to set aria-current when active
mat-tab-group and mat-tab use tablist and tab roles and sets aria-selected properly https://material.angular.io/components/tabs/overview. mat-tab-nav-bar and mat-tab-link use nav and link roles and are missing corresponding aria-current.
1 parent 9f6aa84 commit 83043a0

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,23 @@ describe('MatTabNavBar', () => {
6767
fixture.detectChanges();
6868
expect(tabLinkElements[0].classList.contains('mat-tab-label-active')).toBeFalsy();
6969
expect(tabLinkElements[1].classList.contains('mat-tab-label-active')).toBeTruthy();
70+
});
71+
72+
it('should toggle aria-current based on active state', () => {
73+
let tabLink1 = fixture.debugElement.queryAll(By.css('a'))[0];
74+
let tabLink2 = fixture.debugElement.queryAll(By.css('a'))[1];
75+
const tabLinkElements = fixture.debugElement.queryAll(By.css('a'))
76+
.map(tabLinkDebugEl => tabLinkDebugEl.nativeElement);
7077

78+
tabLink1.nativeElement.click();
79+
fixture.detectChanges();
80+
expect(tabLinkElements[0].getAttribute('aria-current')).toEqual('true');
81+
expect(tabLinkElements[1].getAttribute('aria-current')).toEqual('false');
82+
83+
tabLink2.nativeElement.click();
84+
fixture.detectChanges();
85+
expect(tabLinkElements[0].getAttribute('aria-current')).toEqual('false');
86+
expect(tabLinkElements[1].getAttribute('aria-current')).toEqual('true');
7187
});
7288

7389
it('should add the disabled class if disabled', () => {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export const _MatTabLinkMixinBase =
172172
inputs: ['disabled', 'disableRipple', 'tabIndex'],
173173
host: {
174174
'class': 'mat-tab-link',
175-
'role': 'tab',
175+
'[attr.aria-current]': 'active',
176176
'[attr.aria-disabled]': 'disabled.toString()',
177177
'[attr.tabIndex]': 'tabIndex',
178178
'[class.mat-tab-disabled]': 'disabled',

0 commit comments

Comments
 (0)