@@ -14,6 +14,7 @@ import {
14
14
ViewEncapsulation ,
15
15
ViewChild ,
16
16
ChangeDetectorRef ,
17
+ Attribute ,
17
18
} from '@angular/core' ;
18
19
import { MdOption , MdOptionSelectionChange } from '../core/option/option' ;
19
20
import { ENTER , SPACE } from '../core/keyboard/keycodes' ;
@@ -99,7 +100,7 @@ export type MdSelectFloatPlaceholderType = 'always' | 'never' | 'auto';
99
100
encapsulation : ViewEncapsulation . None ,
100
101
host : {
101
102
'role' : 'listbox' ,
102
- '[attr.tabindex]' : '_getTabIndex() ' ,
103
+ '[attr.tabindex]' : 'tabIndex ' ,
103
104
'[attr.aria-label]' : 'placeholder' ,
104
105
'[attr.aria-required]' : 'required.toString()' ,
105
106
'[attr.aria-disabled]' : 'disabled.toString()' ,
@@ -151,6 +152,9 @@ export class MdSelect implements AfterContentInit, ControlValueAccessor, OnDestr
151
152
/** The animation state of the placeholder. */
152
153
private _placeholderState = '' ;
153
154
155
+ /** Tab index for the element. */
156
+ private _tabIndex : number ;
157
+
154
158
/**
155
159
* The width of the trigger. Must be saved to set the min width of the overlay panel
156
160
* and the width of the selected value.
@@ -266,6 +270,15 @@ export class MdSelect implements AfterContentInit, ControlValueAccessor, OnDestr
266
270
}
267
271
private _floatPlaceholder : MdSelectFloatPlaceholderType = 'auto' ;
268
272
273
+ /** Tab index for the select element. */
274
+ @Input ( )
275
+ get tabIndex ( ) : number { return this . _disabled ? - 1 : this . _tabIndex ; }
276
+ set tabIndex ( value : number ) {
277
+ if ( typeof value !== 'undefined' ) {
278
+ this . _tabIndex = value ;
279
+ }
280
+ }
281
+
269
282
/** Combined stream of all of the child options' change events. */
270
283
get optionSelectionChanges ( ) : Observable < MdOptionSelectionChange > {
271
284
return Observable . merge ( ...this . options . map ( option => option . onSelectionChange ) ) ;
@@ -282,10 +295,13 @@ export class MdSelect implements AfterContentInit, ControlValueAccessor, OnDestr
282
295
283
296
constructor ( private _element : ElementRef , private _renderer : Renderer ,
284
297
private _viewportRuler : ViewportRuler , private _changeDetectorRef : ChangeDetectorRef ,
285
- @Optional ( ) private _dir : Dir , @Self ( ) @Optional ( ) public _control : NgControl ) {
298
+ @Optional ( ) private _dir : Dir , @Self ( ) @Optional ( ) public _control : NgControl ,
299
+ @Attribute ( 'tabindex' ) tabIndex : string ) {
286
300
if ( this . _control ) {
287
301
this . _control . valueAccessor = this ;
288
302
}
303
+
304
+ this . _tabIndex = parseInt ( tabIndex ) || 0 ;
289
305
}
290
306
291
307
ngAfterContentInit ( ) {
@@ -452,12 +468,6 @@ export class MdSelect implements AfterContentInit, ControlValueAccessor, OnDestr
452
468
}
453
469
}
454
470
455
- /** Returns the correct tabindex for the select depending on disabled state. */
456
- _getTabIndex ( ) {
457
- return this . disabled ? '-1' : '0' ;
458
- }
459
-
460
-
461
471
/**
462
472
* Sets the scroll position of the scroll container. This must be called after
463
473
* the overlay pane is attached or the scroll container element will not yet be
0 commit comments