@@ -23,6 +23,7 @@ import {
23
23
OnDestroy ,
24
24
forwardRef ,
25
25
Inject ,
26
+ Attribute ,
26
27
} from '@angular/core' ;
27
28
import { coerceBooleanProperty , SelectionModel , MdLine , MdLineSetter } from '../core' ;
28
29
import { FocusKeyManager } from '../core/a11y/focus-key-manager' ;
@@ -34,11 +35,13 @@ import {RxChain, switchMap, startWith} from '../core/rxjs/index';
34
35
import { merge } from 'rxjs/observable/merge' ;
35
36
import { CanDisableRipple , mixinDisableRipple } from '../core/common-behaviors/disable-ripple' ;
36
37
import { MATERIAL_COMPATIBILITY_MODE } from '../core/compatibility/compatibility' ;
38
+ import { mixinTabIndex , HasTabIndex } from '../core/common-behaviors/tabindex' ;
37
39
38
40
39
41
/** @docs -private */
40
42
export class MdSelectionListBase { }
41
- export const _MdSelectionListMixinBase = mixinDisableRipple ( mixinDisabled ( MdSelectionListBase ) ) ;
43
+ export const _MdSelectionListMixinBase =
44
+ mixinTabIndex ( mixinDisableRipple ( mixinDisabled ( MdSelectionListBase ) ) ) ;
42
45
43
46
/** @docs -private */
44
47
export class MdListOptionBase { }
@@ -182,10 +185,10 @@ export class MdListOption extends _MdListOptionMixinBase
182
185
@Component ( {
183
186
moduleId : module . id ,
184
187
selector : 'md-selection-list, mat-selection-list' ,
185
- inputs : [ 'disabled' , 'disableRipple' ] ,
188
+ inputs : [ 'disabled' , 'disableRipple' , 'tabIndex' ] ,
186
189
host : {
187
190
'role' : 'listbox' ,
188
- '[attr.tabindex ]' : '_tabIndex ' ,
191
+ '[tabIndex ]' : 'tabIndex ' ,
189
192
'class' : 'mat-selection-list' ,
190
193
'(focus)' : 'focus()' ,
191
194
'(keydown)' : '_keydown($event)' ,
@@ -195,11 +198,8 @@ export class MdListOption extends _MdListOptionMixinBase
195
198
encapsulation : ViewEncapsulation . None ,
196
199
changeDetection : ChangeDetectionStrategy . OnPush
197
200
} )
198
- export class MdSelectionList extends _MdSelectionListMixinBase
199
- implements FocusableOption , CanDisable , CanDisableRipple , AfterContentInit , OnDestroy {
200
-
201
- /** Tab index for the selection-list. */
202
- _tabIndex = 0 ;
201
+ export class MdSelectionList extends _MdSelectionListMixinBase implements FocusableOption ,
202
+ CanDisable , CanDisableRipple , HasTabIndex , AfterContentInit , OnDestroy {
203
203
204
204
/** Subscription to all list options' onFocus events */
205
205
private _optionFocusSubscription = Subscription . EMPTY ;
@@ -216,17 +216,15 @@ export class MdSelectionList extends _MdSelectionListMixinBase
216
216
/** The currently selected options. */
217
217
selectedOptions : SelectionModel < MdListOption > = new SelectionModel < MdListOption > ( true ) ;
218
218
219
- constructor ( private _element : ElementRef ) {
219
+ constructor ( private _element : ElementRef , @ Attribute ( 'tabindex' ) tabIndex : string ) {
220
220
super ( ) ;
221
+
222
+ this . tabIndex = parseInt ( tabIndex ) || 0 ;
221
223
}
222
224
223
225
ngAfterContentInit ( ) : void {
224
226
this . _keyManager = new FocusKeyManager < MdListOption > ( this . options ) . withWrap ( ) ;
225
227
226
- if ( this . disabled ) {
227
- this . _tabIndex = - 1 ;
228
- }
229
-
230
228
this . _optionFocusSubscription = this . _onFocusSubscription ( ) ;
231
229
this . _optionDestroyStream = this . _onDestroySubscription ( ) ;
232
230
}
0 commit comments