Skip to content

Commit fd23c02

Browse files
stevenyxujosephperrott
authored andcommitted
fix(tabs): Add role to mat-tab-nav-bar and mat-tab-link (#11410)
1 parent 4ef9cb0 commit fd23c02

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<div class="mat-tab-links" (cdkObserveContent)="_alignInkBar()">
1+
<div class="mat-tab-links" (cdkObserveContent)="_alignInkBar()" role="tablist">
22
<ng-content></ng-content>
33
<mat-ink-bar></mat-ink-bar>
44
</div>
5-

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ describe('MatTabNavBar', () => {
1616
imports: [MatTabsModule],
1717
declarations: [
1818
SimpleTabNavBarTestApp,
19+
TabLink,
1920
TabLinkWithNgIf,
2021
TabLinkWithTabIndexBinding,
2122
TabLinkWithNativeTabindexAttr,
@@ -273,6 +274,16 @@ describe('MatTabNavBar', () => {
273274

274275
expect(tabLink.tabIndex).toBe(3, 'Expected the tabIndex to be have been set to 3.');
275276
});
277+
278+
it('should set role on tablist and tab', () => {
279+
const fixture = TestBed.createComponent(TabLink);
280+
fixture.detectChanges();
281+
282+
const tabList = fixture.debugElement.query(By.css('.mat-tab-links'));
283+
expect(tabList.nativeElement.getAttribute('role')).toEqual('tablist');
284+
const tabLinkElement = tabList.query(By.directive(MatTabLink)).nativeElement;
285+
expect(tabLinkElement.getAttribute('role')).toEqual('tab');
286+
});
276287
});
277288

278289
@Component({
@@ -301,6 +312,15 @@ class SimpleTabNavBarTestApp {
301312
activeIndex = 0;
302313
}
303314

315+
@Component({
316+
template: `
317+
<nav mat-tab-nav-bar>
318+
<a mat-tab-link role="willbeoverridden">Link</a>
319+
</nav>
320+
`
321+
})
322+
class TabLink {}
323+
304324
@Component({
305325
template: `
306326
<nav mat-tab-nav-bar>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ export const _MatTabLinkMixinBase =
172172
inputs: ['disabled', 'disableRipple', 'tabIndex'],
173173
host: {
174174
'class': 'mat-tab-link',
175+
'role': 'tab',
175176
'[attr.aria-disabled]': 'disabled.toString()',
176177
'[attr.tabIndex]': 'tabIndex',
177178
'[class.mat-tab-disabled]': 'disabled',

0 commit comments

Comments
 (0)