@@ -4,7 +4,7 @@ import {By} from '@angular/platform-browser';
44import { dispatchFakeEvent , dispatchMouseEvent } from '@angular/cdk/testing' ;
55import { Direction , Directionality } from '@angular/cdk/bidi' ;
66import { Subject } from 'rxjs/Subject' ;
7- import { MatTabNav , MatTabsModule , MatTabLink } from '../index' ;
7+ import { MatTabLink , MatTabNav , MatTabsModule } from '../index' ;
88
99
1010describe ( 'MatTabNavBar' , ( ) => {
@@ -17,6 +17,8 @@ describe('MatTabNavBar', () => {
1717 declarations : [
1818 SimpleTabNavBarTestApp ,
1919 TabLinkWithNgIf ,
20+ TabLinkWithTabIndexBinding ,
21+ TabLinkWithNativeTabindexAttr ,
2022 ] ,
2123 providers : [
2224 { provide : Directionality , useFactory : ( ) => ( {
@@ -119,9 +121,7 @@ describe('MatTabNavBar', () => {
119121 fixture . componentInstance . disabled = true ;
120122 fixture . detectChanges ( ) ;
121123
122- expect ( tabLinkElements . every ( tabLink => {
123- return tabLink . getAttribute ( 'tabIndex' ) === null ;
124- } ) )
124+ expect ( tabLinkElements . every ( tabLink => tabLink . tabIndex === - 1 ) )
125125 . toBe ( true , 'Expected element to no longer be keyboard focusable if disabled.' ) ;
126126 } ) ;
127127
@@ -212,6 +212,30 @@ describe('MatTabNavBar', () => {
212212 expect ( link . querySelector ( '.mat-ripple-element' ) )
213213 . toBeFalsy ( 'Expected no ripple to be created when ripple target is destroyed.' ) ;
214214 } ) ;
215+
216+ it ( 'should support the native tabindex attribute' , ( ) => {
217+ const fixture = TestBed . createComponent ( TabLinkWithNativeTabindexAttr ) ;
218+ fixture . detectChanges ( ) ;
219+
220+ const tabLink = fixture . debugElement . query ( By . directive ( MatTabLink ) ) . injector . get ( MatTabLink ) ;
221+
222+ expect ( tabLink . tabIndex )
223+ . toBe ( 5 , 'Expected the tabIndex to be set from the native tabindex attribute.' ) ;
224+ } ) ;
225+
226+ it ( 'should support binding to the tabIndex' , ( ) => {
227+ const fixture = TestBed . createComponent ( TabLinkWithTabIndexBinding ) ;
228+ fixture . detectChanges ( ) ;
229+
230+ const tabLink = fixture . debugElement . query ( By . directive ( MatTabLink ) ) . injector . get ( MatTabLink ) ;
231+
232+ expect ( tabLink . tabIndex ) . toBe ( 0 , 'Expected the tabIndex to be set to 0 by default.' ) ;
233+
234+ fixture . componentInstance . tabIndex = 3 ;
235+ fixture . detectChanges ( ) ;
236+
237+ expect ( tabLink . tabIndex ) . toBe ( 3 , 'Expected the tabIndex to be have been set to 3.' ) ;
238+ } ) ;
215239} ) ;
216240
217241@Component ( {
@@ -249,3 +273,23 @@ class SimpleTabNavBarTestApp {
249273class TabLinkWithNgIf {
250274 isDestroyed = false ;
251275}
276+
277+ @Component ( {
278+ template : `
279+ <nav mat-tab-nav-bar>
280+ <a mat-tab-link [tabIndex]="tabIndex">TabIndex Link</a>
281+ </nav>
282+ `
283+ } )
284+ class TabLinkWithTabIndexBinding {
285+ tabIndex = 0 ;
286+ }
287+
288+ @Component ( {
289+ template : `
290+ <nav mat-tab-nav-bar>
291+ <a mat-tab-link tabindex="5">Link</a>
292+ </nav>
293+ `
294+ } )
295+ class TabLinkWithNativeTabindexAttr { }
0 commit comments