@@ -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 { }
@@ -188,10 +192,10 @@ export class MatListOption extends _MatListOptionMixinBase
188192 moduleId : module . id ,
189193 selector : 'mat-selection-list' ,
190194 exportAs : 'matSelectionList' ,
191- inputs : [ 'disabled' , 'disableRipple' ] ,
195+ inputs : [ 'disabled' , 'disableRipple' , 'tabIndex' ] ,
192196 host : {
193197 'role' : 'listbox' ,
194- '[attr.tabindex ]' : '_tabIndex ' ,
198+ '[tabIndex ]' : 'tabIndex ' ,
195199 'class' : 'mat-selection-list' ,
196200 '(focus)' : 'focus()' ,
197201 '(keydown)' : '_keydown($event)' ,
@@ -202,11 +206,8 @@ export class MatListOption extends _MatListOptionMixinBase
202206 preserveWhitespaces : false ,
203207 changeDetection : ChangeDetectionStrategy . OnPush
204208} )
205- export class MatSelectionList extends _MatSelectionListMixinBase
206- implements FocusableOption , CanDisable , CanDisableRipple , AfterContentInit {
207-
208- /** Tab index for the selection-list. */
209- _tabIndex = 0 ;
209+ export class MatSelectionList extends _MatSelectionListMixinBase implements FocusableOption ,
210+ CanDisable , CanDisableRipple , HasTabIndex , AfterContentInit {
210211
211212 /** The FocusKeyManager which handles focus. */
212213 _keyManager : FocusKeyManager < MatListOption > ;
@@ -217,16 +218,14 @@ export class MatSelectionList extends _MatSelectionListMixinBase
217218 /** The currently selected options. */
218219 selectedOptions : SelectionModel < MatListOption > = new SelectionModel < MatListOption > ( true ) ;
219220
220- constructor ( private _element : ElementRef ) {
221+ constructor ( private _element : ElementRef , @ Attribute ( 'tabindex' ) tabIndex : string ) {
221222 super ( ) ;
223+
224+ this . tabIndex = parseInt ( tabIndex ) || 0 ;
222225 }
223226
224227 ngAfterContentInit ( ) : void {
225228 this . _keyManager = new FocusKeyManager < MatListOption > ( this . options ) . withWrap ( ) ;
226-
227- if ( this . disabled ) {
228- this . _tabIndex = - 1 ;
229- }
230229 }
231230
232231 /** Focus the selection-list. */
0 commit comments