Skip to content

Commit a9c1db6

Browse files
committed
fix(tabs): update mat-tab-link to set aria-selected when active
mat-tab-header already does this: https://github.com/angular/material2/blob/abc3d38c57146443c848d5ba26fd2fab8ca185d6/src/lib/tabs/tab-group.html#L11 And you can see aria-selected is being set properly on the main tabs demo page https://material.angular.io/components/tabs/overview. But mat-tab-nav-bar (on the same page, but no live demo) doesn't set aria-selected at all.
1 parent 69e4ca7 commit a9c1db6

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
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
@@ -66,7 +66,23 @@ describe('MatTabNavBar', () => {
6666
fixture.detectChanges();
6767
expect(tabLinkElements[0].classList.contains('mat-tab-label-active')).toBeFalsy();
6868
expect(tabLinkElements[1].classList.contains('mat-tab-label-active')).toBeTruthy();
69+
});
70+
71+
it('should toggle aria-selected based on active state', () => {
72+
let tabLink1 = fixture.debugElement.queryAll(By.css('a'))[0];
73+
let tabLink2 = fixture.debugElement.queryAll(By.css('a'))[1];
74+
const tabLinkElements = fixture.debugElement.queryAll(By.css('a'))
75+
.map(tabLinkDebugEl => tabLinkDebugEl.nativeElement);
6976

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

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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ export const _MatTabLinkMixinBase =
173173
host: {
174174
'class': 'mat-tab-link',
175175
'[attr.aria-disabled]': 'disabled.toString()',
176+
'[attr.aria-selected]': 'active',
176177
'[attr.tabIndex]': 'tabIndex',
177178
'[class.mat-tab-disabled]': 'disabled',
178179
'[class.mat-tab-label-active]': 'active',

0 commit comments

Comments
 (0)