@@ -69,6 +69,15 @@ export abstract class MatListItemBase implements AfterContentInit, OnDestroy, Ri
69
69
this . _monitorLines ( ) ;
70
70
}
71
71
72
+ ngOnDestroy ( ) {
73
+ this . _subscriptions . unsubscribe ( ) ;
74
+ this . _rippleRenderer . _removeTriggerEvents ( ) ;
75
+ }
76
+
77
+ _setTabIndexForChildren ( value : number ) {
78
+ this . _element . querySelectorAll ( 'a, button' ) . forEach ( el => ( el as HTMLElement ) . tabIndex = value ) ;
79
+ }
80
+
72
81
/**
73
82
* Subscribes to changes in `MatLine` content children and annotates them appropriately when they
74
83
* change.
@@ -88,19 +97,18 @@ export abstract class MatListItemBase implements AfterContentInit, OnDestroy, Ri
88
97
} ) ) ;
89
98
} ) ;
90
99
}
91
-
92
- ngOnDestroy ( ) {
93
- this . _subscriptions . unsubscribe ( ) ;
94
- this . _rippleRenderer . _removeTriggerEvents ( ) ;
95
- }
96
100
}
97
101
98
102
@Directive ( )
99
103
/** @docs -private */
100
- export abstract class MatListBase implements AfterViewInit , OnDestroy {
104
+ export abstract class MatListBase {
101
105
@HostBinding ( 'class.mdc-list--non-interactive' )
102
- _isNonInteractive : boolean = false ;
106
+ _isNonInteractive : boolean = true ;
107
+ }
103
108
109
+ @Directive ( )
110
+ export abstract class MatInteractiveListBase extends MatListBase
111
+ implements AfterViewInit , OnDestroy {
104
112
@HostListener ( 'keydown' , [ '$event' ] )
105
113
_handleKeydown ( event : KeyboardEvent ) {
106
114
const index = this . _indexForElement ( event . target as HTMLElement ) ;
@@ -138,7 +146,7 @@ export abstract class MatListBase implements AfterViewInit, OnDestroy {
138
146
setAttributeForElementIndex :
139
147
( index , attr , value ) => this . _itemAtIndex ( index ) . _element . setAttribute ( attr , value ) ,
140
148
setTabIndexForListItemChildren :
141
- ( index , value ) => this . _itemAtIndex ( index ) . _element . tabIndex = value as unknown as number ,
149
+ ( index , value ) => this . _itemAtIndex ( index ) . _setTabIndexForChildren ( Number ( value ) ) ,
142
150
getFocusedElementIndex : ( ) => this . _indexForElement ( this . _document ?. activeELement ) ,
143
151
isFocusInsideList : ( ) => this . _element . nativeElement . contains ( this . _document ?. activeElement ) ,
144
152
isRootFocused : ( ) => this . _element . nativeElement === this . _document ?. activeElement ,
@@ -151,21 +159,27 @@ export abstract class MatListBase implements AfterViewInit, OnDestroy {
151
159
hasRadioAtIndex : ( ) => false ,
152
160
setCheckedCheckboxOrRadioAtIndex : ( ) => { } ,
153
161
isCheckboxCheckedAtIndex : ( ) => false ,
154
- notifyAction : ( ) => { } ,
155
162
156
- // TODO(mmalerba): Determine if we need to implement this .
163
+ // TODO(mmalerba): Determine if we need to implement these .
157
164
getPrimaryTextAtIndex : ( ) => '' ,
165
+ notifyAction : ( ) => { } ,
158
166
} ;
159
167
160
168
protected _foundation : MDCListFoundation ;
161
169
162
170
constructor ( protected _element : ElementRef < HTMLElement > ,
163
- @Inject ( DOCUMENT ) protected _document : any ) {
171
+ @Inject ( DOCUMENT ) protected _document : any ) {
172
+ super ( ) ;
173
+ this . _isNonInteractive = false ;
164
174
this . _foundation = new MDCListFoundation ( this . _adapter ) ;
165
175
}
166
176
167
177
ngAfterViewInit ( ) {
168
178
this . _foundation . init ( ) ;
179
+ const first = this . _items . toArray ( ) [ 0 ] ?. _element ;
180
+ if ( first ) {
181
+ first . tabIndex = 0 ;
182
+ }
169
183
this . _foundation . layout ( ) ;
170
184
}
171
185
@@ -181,3 +195,4 @@ export abstract class MatListBase implements AfterViewInit, OnDestroy {
181
195
return element ? this . _items . toArray ( ) . findIndex ( i => i . _element . contains ( element ) ) : - 1 ;
182
196
}
183
197
}
198
+
0 commit comments