Skip to content

Commit 726fc06

Browse files
authored
fix(material/tabs): add aria-hidden to inactive tabs (#27742)
Make accessibility fix for Tabs component. Add `aria-hidden="true"` to inactive tab panels. Fix issue where chromevox would read the names of inactive tab panels when navigating past the active tab panel (#27741). Fix this by adding `aria-hidden="true"` to inactive tab panels to exclude them from the a11y tree. I believe what was happening is that the inactive tab panels had an aria-labelled by references that pointed to the tab header. Existing behavior seems to be that Chromevox was following the aria-labelledby references and announcing the labels of the inactive tabs. With this commit applied, Chromevox no longer reads panels of inactive tabs. Fix #27741
1 parent 90465a1 commit 726fc06

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/material/tabs/tab-group.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
[id]="_getTabContentId(i)"
5959
[attr.tabindex]="(contentTabIndex != null && selectedIndex === i) ? contentTabIndex : null"
6060
[attr.aria-labelledby]="_getTabLabelId(i)"
61+
[attr.aria-hidden]="selectedIndex !== i"
6162
[class.mat-mdc-tab-body-active]="selectedIndex === i"
6263
[ngClass]="tab.bodyClass"
6364
[content]="tab.content!"

src/material/tabs/tab-group.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,25 @@ describe('MDC-based MatTabGroup', () => {
441441
});
442442
});
443443

444+
describe('aria labelling of tab panels', () => {
445+
let fixture: ComponentFixture<BindedTabsTestApp>;
446+
let tabPanels: HTMLElement[];
447+
448+
beforeEach(fakeAsync(() => {
449+
fixture = TestBed.createComponent(BindedTabsTestApp);
450+
fixture.detectChanges();
451+
tick();
452+
tabPanels = Array.from(fixture.nativeElement.querySelectorAll('.mat-mdc-tab-body'));
453+
}));
454+
455+
it('should set `aria-hidden="true"` on inactive tab panels', () => {
456+
fixture.detectChanges();
457+
458+
expect(tabPanels[0].getAttribute('aria-hidden')).not.toBe('true');
459+
expect(tabPanels[1].getAttribute('aria-hidden')).toBe('true');
460+
});
461+
});
462+
444463
describe('disable tabs', () => {
445464
let fixture: ComponentFixture<DisabledTabsTestApp>;
446465

0 commit comments

Comments
 (0)