Skip to content

Commit

Permalink
fix(material/tabs): add aria-hidden to inactive tabs (#27742)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
zarend authored Sep 4, 2023
1 parent 90465a1 commit 726fc06
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/material/tabs/tab-group.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
[id]="_getTabContentId(i)"
[attr.tabindex]="(contentTabIndex != null && selectedIndex === i) ? contentTabIndex : null"
[attr.aria-labelledby]="_getTabLabelId(i)"
[attr.aria-hidden]="selectedIndex !== i"
[class.mat-mdc-tab-body-active]="selectedIndex === i"
[ngClass]="tab.bodyClass"
[content]="tab.content!"
Expand Down
19 changes: 19 additions & 0 deletions src/material/tabs/tab-group.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,25 @@ describe('MDC-based MatTabGroup', () => {
});
});

describe('aria labelling of tab panels', () => {
let fixture: ComponentFixture<BindedTabsTestApp>;
let tabPanels: HTMLElement[];

beforeEach(fakeAsync(() => {
fixture = TestBed.createComponent(BindedTabsTestApp);
fixture.detectChanges();
tick();
tabPanels = Array.from(fixture.nativeElement.querySelectorAll('.mat-mdc-tab-body'));
}));

it('should set `aria-hidden="true"` on inactive tab panels', () => {
fixture.detectChanges();

expect(tabPanels[0].getAttribute('aria-hidden')).not.toBe('true');
expect(tabPanels[1].getAttribute('aria-hidden')).toBe('true');
});
});

describe('disable tabs', () => {
let fixture: ComponentFixture<DisabledTabsTestApp>;

Expand Down

0 comments on commit 726fc06

Please sign in to comment.