@@ -14,6 +14,7 @@ import {
1414 ViewEncapsulation ,
1515 ViewChild ,
1616 ChangeDetectorRef ,
17+ Attribute ,
1718} from '@angular/core' ;
1819import { MdOption , MdOptionSelectionChange } from '../core/option/option' ;
1920import { ENTER , SPACE } from '../core/keyboard/keycodes' ;
@@ -99,7 +100,7 @@ export type MdSelectFloatPlaceholderType = 'always' | 'never' | 'auto';
99100 encapsulation : ViewEncapsulation . None ,
100101 host : {
101102 'role' : 'listbox' ,
102- '[attr.tabindex]' : '_getTabIndex() ' ,
103+ '[attr.tabindex]' : 'tabIndex ' ,
103104 '[attr.aria-label]' : 'placeholder' ,
104105 '[attr.aria-required]' : 'required.toString()' ,
105106 '[attr.aria-disabled]' : 'disabled.toString()' ,
@@ -151,6 +152,9 @@ export class MdSelect implements AfterContentInit, ControlValueAccessor, OnDestr
151152 /** The animation state of the placeholder. */
152153 private _placeholderState = '' ;
153154
155+ /** Tab index for the element. */
156+ private _tabIndex : number ;
157+
154158 /**
155159 * The width of the trigger. Must be saved to set the min width of the overlay panel
156160 * and the width of the selected value.
@@ -266,6 +270,15 @@ export class MdSelect implements AfterContentInit, ControlValueAccessor, OnDestr
266270 }
267271 private _floatPlaceholder : MdSelectFloatPlaceholderType = 'auto' ;
268272
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+
269282 /** Combined stream of all of the child options' change events. */
270283 get optionSelectionChanges ( ) : Observable < MdOptionSelectionChange > {
271284 return Observable . merge ( ...this . options . map ( option => option . onSelectionChange ) ) ;
@@ -282,10 +295,13 @@ export class MdSelect implements AfterContentInit, ControlValueAccessor, OnDestr
282295
283296 constructor ( private _element : ElementRef , private _renderer : Renderer ,
284297 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 ) {
286300 if ( this . _control ) {
287301 this . _control . valueAccessor = this ;
288302 }
303+
304+ this . _tabIndex = parseInt ( tabIndex ) || 0 ;
289305 }
290306
291307 ngAfterContentInit ( ) {
@@ -452,12 +468,6 @@ export class MdSelect implements AfterContentInit, ControlValueAccessor, OnDestr
452468 }
453469 }
454470
455- /** Returns the correct tabindex for the select depending on disabled state. */
456- _getTabIndex ( ) {
457- return this . disabled ? '-1' : '0' ;
458- }
459-
460-
461471 /**
462472 * Sets the scroll position of the scroll container. This must be called after
463473 * the overlay pane is attached or the scroll container element will not yet be
0 commit comments