@@ -105,6 +105,8 @@ export class TreeKeyManager<T extends TreeKeyManagerItem> {
105
105
/** Function to determine equivalent items. */
106
106
private _trackByFn : ( item : T ) => unknown = ( item : T ) => item ;
107
107
108
+ private _items : Observable < T [ ] > | QueryList < T > | T [ ] ;
109
+
108
110
constructor ( {
109
111
items,
110
112
skipPredicate,
@@ -126,6 +128,8 @@ export class TreeKeyManager<T extends TreeKeyManagerItem> {
126
128
this . _activationFollowsFocus = activationFollowsFocus ;
127
129
}
128
130
131
+ this . _items = items ;
132
+
129
133
// We allow for the items to be an array or Observable because, in some cases, the consumer may
130
134
// not have access to a QueryList of the items they want to manage (e.g. when the
131
135
// items aren't being collected via `ViewChildren` or `ContentChildren`).
@@ -168,6 +172,26 @@ export class TreeKeyManager<T extends TreeKeyManagerItem> {
168
172
return this . _activeItem ;
169
173
}
170
174
175
+ private _setActiveItem ( index : number ) {
176
+ this . _getItems ( )
177
+ . pipe ( take ( 1 ) )
178
+ . subscribe ( items => {
179
+ const activeItem = items [ index ] ;
180
+
181
+ // Explicitly check for `null` and `undefined` because other falsy values are valid.
182
+ this . _activeItem = activeItem == null ? null : activeItem ;
183
+ this . _activeItemIndex = index ;
184
+
185
+ if ( ! this . _activeItem ) {
186
+ return ;
187
+ }
188
+ this . _activeItem . focus ( ) ;
189
+ if ( this . _activationFollowsFocus ) {
190
+ this . _activeItem . activate ( ) ;
191
+ }
192
+ } ) ;
193
+ }
194
+
171
195
private _updateActiveItemIndex ( newItems : T [ ] ) {
172
196
if ( this . _activeItem ) {
173
197
const newIndex = newItems . indexOf ( this . _activeItem ) ;
@@ -177,6 +201,10 @@ export class TreeKeyManager<T extends TreeKeyManagerItem> {
177
201
}
178
202
}
179
203
}
204
+
205
+ private _getItems ( ) : Observable < T [ ] > {
206
+ return coerceObservable ( this . _items ) ;
207
+ }
180
208
}
181
209
182
210
// tslint:enable
0 commit comments