@@ -19,6 +19,7 @@ describe('MatTabGroup', () => {
1919 DisabledTabsTestApp ,
2020 TabGroupWithSimpleApi ,
2121 TemplateTabs ,
22+ TabGroupWithAriaInputs ,
2223 ] ,
2324 } ) ;
2425
@@ -233,6 +234,46 @@ describe('MatTabGroup', () => {
233234
234235 } ) ;
235236
237+ describe ( 'aria labelling' , ( ) => {
238+ let fixture : ComponentFixture < TabGroupWithAriaInputs > ;
239+ let tab : HTMLElement ;
240+
241+ beforeEach ( fakeAsync ( ( ) => {
242+ fixture = TestBed . createComponent ( TabGroupWithAriaInputs ) ;
243+ fixture . detectChanges ( ) ;
244+ tick ( ) ;
245+ tab = fixture . nativeElement . querySelector ( '.mat-tab-label' ) ;
246+ } ) ) ;
247+
248+ it ( 'should not set aria-label or aria-labelledby attributes if they are not passed in' , ( ) => {
249+ expect ( tab . hasAttribute ( 'aria-label' ) ) . toBe ( false ) ;
250+ expect ( tab . hasAttribute ( 'aria-labelledby' ) ) . toBe ( false ) ;
251+ } ) ;
252+
253+ it ( 'should set the aria-label attribute' , ( ) => {
254+ fixture . componentInstance . ariaLabel = 'Fruit' ;
255+ fixture . detectChanges ( ) ;
256+
257+ expect ( tab . getAttribute ( 'aria-label' ) ) . toBe ( 'Fruit' ) ;
258+ } ) ;
259+
260+ it ( 'should set the aria-labelledby attribute' , ( ) => {
261+ fixture . componentInstance . ariaLabelledby = 'fruit-label' ;
262+ fixture . detectChanges ( ) ;
263+
264+ expect ( tab . getAttribute ( 'aria-labelledby' ) ) . toBe ( 'fruit-label' ) ;
265+ } ) ;
266+
267+ it ( 'should not be able to set both an aria-label and aria-labelledby' , ( ) => {
268+ fixture . componentInstance . ariaLabel = 'Fruit' ;
269+ fixture . componentInstance . ariaLabelledby = 'fruit-label' ;
270+ fixture . detectChanges ( ) ;
271+
272+ expect ( tab . getAttribute ( 'aria-label' ) ) . toBe ( 'Fruit' ) ;
273+ expect ( tab . hasAttribute ( 'aria-labelledby' ) ) . toBe ( false ) ;
274+ } ) ;
275+ } ) ;
276+
236277 describe ( 'disable tabs' , ( ) => {
237278 let fixture : ComponentFixture < DisabledTabsTestApp > ;
238279 beforeEach ( ( ) => {
@@ -661,3 +702,16 @@ class NestedTabs {}
661702 ` ,
662703 } )
663704 class TemplateTabs { }
705+
706+
707+ @Component ( {
708+ template : `
709+ <mat-tab-group>
710+ <mat-tab [aria-label]="ariaLabel" [aria-labelledby]="ariaLabelledby"></mat-tab>
711+ </mat-tab-group>
712+ `
713+ } )
714+ class TabGroupWithAriaInputs {
715+ ariaLabel : string ;
716+ ariaLabelledby : string ;
717+ }
0 commit comments