@@ -4,7 +4,7 @@ import {By} from '@angular/platform-browser';
4
4
import { dispatchFakeEvent , dispatchMouseEvent } from '@angular/cdk/testing' ;
5
5
import { Direction , Directionality } from '@angular/cdk/bidi' ;
6
6
import { Subject } from 'rxjs/Subject' ;
7
- import { MatTabNav , MatTabsModule , MatTabLink } from '../index' ;
7
+ import { MatTabLink , MatTabNav , MatTabsModule } from '../index' ;
8
8
9
9
10
10
describe ( 'MatTabNavBar' , ( ) => {
@@ -17,6 +17,8 @@ describe('MatTabNavBar', () => {
17
17
declarations : [
18
18
SimpleTabNavBarTestApp ,
19
19
TabLinkWithNgIf ,
20
+ TabLinkWithTabIndexBinding ,
21
+ TabLinkWithNativeTabindexAttr ,
20
22
] ,
21
23
providers : [
22
24
{ provide : Directionality , useFactory : ( ) => ( {
@@ -119,9 +121,7 @@ describe('MatTabNavBar', () => {
119
121
fixture . componentInstance . disabled = true ;
120
122
fixture . detectChanges ( ) ;
121
123
122
- expect ( tabLinkElements . every ( tabLink => {
123
- return tabLink . getAttribute ( 'tabIndex' ) === null ;
124
- } ) )
124
+ expect ( tabLinkElements . every ( tabLink => tabLink . tabIndex === - 1 ) )
125
125
. toBe ( true , 'Expected element to no longer be keyboard focusable if disabled.' ) ;
126
126
} ) ;
127
127
@@ -212,6 +212,30 @@ describe('MatTabNavBar', () => {
212
212
expect ( link . querySelector ( '.mat-ripple-element' ) )
213
213
. toBeFalsy ( 'Expected no ripple to be created when ripple target is destroyed.' ) ;
214
214
} ) ;
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
+ } ) ;
215
239
} ) ;
216
240
217
241
@Component ( {
@@ -249,3 +273,23 @@ class SimpleTabNavBarTestApp {
249
273
class TabLinkWithNgIf {
250
274
isDestroyed = false ;
251
275
}
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