@@ -12,6 +12,7 @@ import {SelectionModel} from '@angular/cdk/collections';
1212import { SPACE } from '@angular/cdk/keycodes' ;
1313import {
1414 AfterContentInit ,
15+ Attribute ,
1516 ChangeDetectionStrategy ,
1617 ChangeDetectorRef ,
1718 Component ,
@@ -32,16 +33,19 @@ import {
3233import {
3334 CanDisable ,
3435 CanDisableRipple ,
36+ HasTabIndex ,
3537 MatLine ,
3638 MatLineSetter ,
3739 mixinDisabled ,
3840 mixinDisableRipple ,
41+ mixinTabIndex ,
3942} from '@angular/material/core' ;
4043
4144
4245/** @docs -private */
4346export class MatSelectionListBase { }
44- export const _MatSelectionListMixinBase = mixinDisableRipple ( mixinDisabled ( MatSelectionListBase ) ) ;
47+ export const _MatSelectionListMixinBase =
48+ mixinTabIndex ( mixinDisableRipple ( mixinDisabled ( MatSelectionListBase ) ) ) ;
4549
4650/** @docs -private */
4751export class MatListOptionBase { }
@@ -178,10 +182,10 @@ export class MatListOption extends _MatListOptionMixinBase
178182@Component ( {
179183 moduleId : module . id ,
180184 selector : 'mat-selection-list' ,
181- inputs : [ 'disabled' , 'disableRipple' ] ,
185+ inputs : [ 'disabled' , 'disableRipple' , 'tabIndex' ] ,
182186 host : {
183187 'role' : 'listbox' ,
184- '[attr.tabindex ]' : '_tabIndex ' ,
188+ '[tabIndex ]' : 'tabIndex ' ,
185189 'class' : 'mat-selection-list' ,
186190 '(focus)' : 'focus()' ,
187191 '(keydown)' : '_keydown($event)' ,
@@ -192,11 +196,8 @@ export class MatListOption extends _MatListOptionMixinBase
192196 preserveWhitespaces : false ,
193197 changeDetection : ChangeDetectionStrategy . OnPush
194198} )
195- export class MatSelectionList extends _MatSelectionListMixinBase
196- implements FocusableOption , CanDisable , CanDisableRipple , AfterContentInit {
197-
198- /** Tab index for the selection-list. */
199- _tabIndex = 0 ;
199+ export class MatSelectionList extends _MatSelectionListMixinBase implements FocusableOption ,
200+ CanDisable , CanDisableRipple , HasTabIndex , AfterContentInit {
200201
201202 /** The FocusKeyManager which handles focus. */
202203 _keyManager : FocusKeyManager < MatListOption > ;
@@ -207,16 +208,14 @@ export class MatSelectionList extends _MatSelectionListMixinBase
207208 /** The currently selected options. */
208209 selectedOptions : SelectionModel < MatListOption > = new SelectionModel < MatListOption > ( true ) ;
209210
210- constructor ( private _element : ElementRef ) {
211+ constructor ( private _element : ElementRef , @ Attribute ( 'tabindex' ) tabIndex : string ) {
211212 super ( ) ;
213+
214+ this . tabIndex = parseInt ( tabIndex ) || 0 ;
212215 }
213216
214217 ngAfterContentInit ( ) : void {
215218 this . _keyManager = new FocusKeyManager < MatListOption > ( this . options ) . withWrap ( ) ;
216-
217- if ( this . disabled ) {
218- this . _tabIndex = - 1 ;
219- }
220219 }
221220
222221 /** Focus the selection-list. */
0 commit comments