@@ -12,6 +12,7 @@ import {SelectionModel} from '@angular/cdk/collections';
12
12
import { SPACE } from '@angular/cdk/keycodes' ;
13
13
import {
14
14
AfterContentInit ,
15
+ Attribute ,
15
16
ChangeDetectionStrategy ,
16
17
ChangeDetectorRef ,
17
18
Component ,
@@ -32,16 +33,19 @@ import {
32
33
import {
33
34
CanDisable ,
34
35
CanDisableRipple ,
36
+ HasTabIndex ,
35
37
MatLine ,
36
38
MatLineSetter ,
37
39
mixinDisabled ,
38
40
mixinDisableRipple ,
41
+ mixinTabIndex ,
39
42
} from '@angular/material/core' ;
40
43
41
44
42
45
/** @docs -private */
43
46
export class MatSelectionListBase { }
44
- export const _MatSelectionListMixinBase = mixinDisableRipple ( mixinDisabled ( MatSelectionListBase ) ) ;
47
+ export const _MatSelectionListMixinBase =
48
+ mixinTabIndex ( mixinDisableRipple ( mixinDisabled ( MatSelectionListBase ) ) ) ;
45
49
46
50
/** @docs -private */
47
51
export class MatListOptionBase { }
@@ -188,10 +192,10 @@ export class MatListOption extends _MatListOptionMixinBase
188
192
moduleId : module . id ,
189
193
selector : 'mat-selection-list' ,
190
194
exportAs : 'matSelectionList' ,
191
- inputs : [ 'disabled' , 'disableRipple' ] ,
195
+ inputs : [ 'disabled' , 'disableRipple' , 'tabIndex' ] ,
192
196
host : {
193
197
'role' : 'listbox' ,
194
- '[attr.tabindex ]' : '_tabIndex ' ,
198
+ '[tabIndex ]' : 'tabIndex ' ,
195
199
'class' : 'mat-selection-list' ,
196
200
'(focus)' : 'focus()' ,
197
201
'(keydown)' : '_keydown($event)' ,
@@ -202,11 +206,8 @@ export class MatListOption extends _MatListOptionMixinBase
202
206
preserveWhitespaces : false ,
203
207
changeDetection : ChangeDetectionStrategy . OnPush
204
208
} )
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 {
210
211
211
212
/** The FocusKeyManager which handles focus. */
212
213
_keyManager : FocusKeyManager < MatListOption > ;
@@ -217,16 +218,14 @@ export class MatSelectionList extends _MatSelectionListMixinBase
217
218
/** The currently selected options. */
218
219
selectedOptions : SelectionModel < MatListOption > = new SelectionModel < MatListOption > ( true ) ;
219
220
220
- constructor ( private _element : ElementRef ) {
221
+ constructor ( private _element : ElementRef , @ Attribute ( 'tabindex' ) tabIndex : string ) {
221
222
super ( ) ;
223
+
224
+ this . tabIndex = parseInt ( tabIndex ) || 0 ;
222
225
}
223
226
224
227
ngAfterContentInit ( ) : void {
225
228
this . _keyManager = new FocusKeyManager < MatListOption > ( this . options ) . withWrap ( ) ;
226
-
227
- if ( this . disabled ) {
228
- this . _tabIndex = - 1 ;
229
- }
230
229
}
231
230
232
231
/** Focus the selection-list. */
0 commit comments