@@ -49,14 +49,8 @@ export abstract class MatListItemBase implements AfterContentInit, OnDestroy, Ri
49
49
private _rippleRenderer : RippleRenderer ;
50
50
51
51
protected constructor ( public _elementRef : ElementRef < HTMLElement > , protected _ngZone : NgZone ,
52
- listBase : MatListBase , platform : Platform ) {
53
- this . rippleDisabled = listBase . _isNonInteractive ;
54
- if ( ! listBase . _isNonInteractive ) {
55
- this . _elementRef . nativeElement . classList . add ( 'mat-mdc-list-item-interactive' ) ;
56
- }
57
- this . _rippleRenderer =
58
- new RippleRenderer ( this , this . _ngZone , this . _elementRef . nativeElement , platform ) ;
59
- this . _rippleRenderer . setupTriggerEvents ( this . _elementRef . nativeElement ) ;
52
+ private _listBase : MatListBase , private _platform : Platform ) {
53
+ this . _initRipple ( ) ;
60
54
}
61
55
62
56
ngAfterContentInit ( ) {
@@ -68,6 +62,23 @@ export abstract class MatListItemBase implements AfterContentInit, OnDestroy, Ri
68
62
this . _rippleRenderer . _removeTriggerEvents ( ) ;
69
63
}
70
64
65
+ _initDefaultTabIndex ( tabIndex : number ) {
66
+ const el = this . _elementRef . nativeElement ;
67
+ if ( ! el . hasAttribute ( 'tabIndex' ) ) {
68
+ el . tabIndex = tabIndex ;
69
+ }
70
+ }
71
+
72
+ private _initRipple ( ) {
73
+ this . rippleDisabled = this . _listBase . _isNonInteractive ;
74
+ if ( ! this . _listBase . _isNonInteractive ) {
75
+ this . _elementRef . nativeElement . classList . add ( 'mat-mdc-list-item-interactive' ) ;
76
+ }
77
+ this . _rippleRenderer =
78
+ new RippleRenderer ( this , this . _ngZone , this . _elementRef . nativeElement , this . _platform ) ;
79
+ this . _rippleRenderer . setupTriggerEvents ( this . _elementRef . nativeElement ) ;
80
+ }
81
+
71
82
/**
72
83
* Subscribes to changes in `MatLine` content children and annotates them appropriately when they
73
84
* change.
@@ -177,13 +188,8 @@ export abstract class MatInteractiveListBase extends MatListBase
177
188
}
178
189
179
190
ngAfterViewInit ( ) {
180
- this . _subscriptions . add (
181
- this . _items . changes . pipe ( startWith ( null ) )
182
- . subscribe ( ( ) => this . _itemsArr = this . _items . toArray ( ) ) ) ;
191
+ this . _initItems ( ) ;
183
192
this . _foundation . init ( ) ;
184
- for ( let i = 0 ; this . _items . length ; i ++ ) {
185
- this . _elementAtIndex ( i ) . tabIndex = i === 0 ? 0 : - 1 ;
186
- }
187
193
this . _foundation . layout ( ) ;
188
194
}
189
195
@@ -192,6 +198,15 @@ export abstract class MatInteractiveListBase extends MatListBase
192
198
this . _subscriptions . unsubscribe ( ) ;
193
199
}
194
200
201
+ private _initItems ( ) {
202
+ this . _subscriptions . add (
203
+ this . _items . changes . pipe ( startWith ( null ) )
204
+ . subscribe ( ( ) => this . _itemsArr = this . _items . toArray ( ) ) ) ;
205
+ for ( let i = 0 ; this . _itemsArr . length ; i ++ ) {
206
+ this . _itemsArr [ i ] . _initDefaultTabIndex ( i === 0 ? 0 : - 1 ) ;
207
+ }
208
+ }
209
+
195
210
private _itemAtIndex ( index : number ) : MatListItemBase {
196
211
return this . _itemsArr [ index ] ;
197
212
}
0 commit comments