@@ -39,7 +39,7 @@ export type ListKeyManagerModifierKey = 'altKey' | 'ctrlKey' | 'metaKey' | 'shif
39
39
* of items, it will set the active item correctly when arrow events occur.
40
40
*/
41
41
export class ListKeyManager < T extends ListKeyManagerOption > {
42
- private _activeItemIndex = - 1 ;
42
+ private _activeItemIndex = signal ( - 1 ) ;
43
43
private _activeItem = signal < T | null > ( null ) ;
44
44
private _wrap = false ;
45
45
private _typeaheadSubscription = Subscription . EMPTY ;
@@ -209,7 +209,7 @@ export class ListKeyManager<T extends ListKeyManagerOption> {
209
209
this . updateActiveItem ( item ) ;
210
210
211
211
if ( this . _activeItem ( ) !== previousActiveItem ) {
212
- this . change . next ( this . _activeItemIndex ) ;
212
+ this . change . next ( this . _activeItemIndex ( ) ) ;
213
213
}
214
214
}
215
215
@@ -279,7 +279,7 @@ export class ListKeyManager<T extends ListKeyManagerOption> {
279
279
280
280
case PAGE_UP :
281
281
if ( this . _pageUpAndDown . enabled && isModifierAllowed ) {
282
- const targetIndex = this . _activeItemIndex - this . _pageUpAndDown . delta ;
282
+ const targetIndex = this . _activeItemIndex ( ) - this . _pageUpAndDown . delta ;
283
283
this . _setActiveItemByIndex ( targetIndex > 0 ? targetIndex : 0 , 1 ) ;
284
284
break ;
285
285
} else {
@@ -288,7 +288,7 @@ export class ListKeyManager<T extends ListKeyManagerOption> {
288
288
289
289
case PAGE_DOWN :
290
290
if ( this . _pageUpAndDown . enabled && isModifierAllowed ) {
291
- const targetIndex = this . _activeItemIndex + this . _pageUpAndDown . delta ;
291
+ const targetIndex = this . _activeItemIndex ( ) + this . _pageUpAndDown . delta ;
292
292
const itemsLength = this . _getItemsArray ( ) . length ;
293
293
this . _setActiveItemByIndex ( targetIndex < itemsLength ? targetIndex : itemsLength - 1 , - 1 ) ;
294
294
break ;
@@ -312,7 +312,7 @@ export class ListKeyManager<T extends ListKeyManagerOption> {
312
312
313
313
/** Index of the currently active item. */
314
314
get activeItemIndex ( ) : number | null {
315
- return this . _activeItemIndex ;
315
+ return this . _activeItemIndex ( ) ;
316
316
}
317
317
318
318
/** The active item. */
@@ -337,12 +337,12 @@ export class ListKeyManager<T extends ListKeyManagerOption> {
337
337
338
338
/** Sets the active item to the next enabled item in the list. */
339
339
setNextItemActive ( ) : void {
340
- this . _activeItemIndex < 0 ? this . setFirstItemActive ( ) : this . _setActiveItemByDelta ( 1 ) ;
340
+ this . _activeItemIndex ( ) < 0 ? this . setFirstItemActive ( ) : this . _setActiveItemByDelta ( 1 ) ;
341
341
}
342
342
343
343
/** Sets the active item to a previous enabled item in the list. */
344
344
setPreviousItemActive ( ) : void {
345
- this . _activeItemIndex < 0 && this . _wrap
345
+ this . _activeItemIndex ( ) < 0 && this . _wrap
346
346
? this . setLastItemActive ( )
347
347
: this . _setActiveItemByDelta ( - 1 ) ;
348
348
}
@@ -366,7 +366,7 @@ export class ListKeyManager<T extends ListKeyManagerOption> {
366
366
367
367
// Explicitly check for `null` and `undefined` because other falsy values are valid.
368
368
this . _activeItem . set ( activeItem == null ? null : activeItem ) ;
369
- this . _activeItemIndex = index ;
369
+ this . _activeItemIndex . set ( index ) ;
370
370
this . _typeahead ?. setCurrentSelectedItemIndex ( index ) ;
371
371
}
372
372
@@ -398,7 +398,7 @@ export class ListKeyManager<T extends ListKeyManagerOption> {
398
398
const items = this . _getItemsArray ( ) ;
399
399
400
400
for ( let i = 1 ; i <= items . length ; i ++ ) {
401
- const index = ( this . _activeItemIndex + delta * i + items . length ) % items . length ;
401
+ const index = ( this . _activeItemIndex ( ) + delta * i + items . length ) % items . length ;
402
402
const item = items [ index ] ;
403
403
404
404
if ( ! this . _skipPredicateFn ( item ) ) {
@@ -414,7 +414,7 @@ export class ListKeyManager<T extends ListKeyManagerOption> {
414
414
* it encounters either end of the list, it will stop and not wrap.
415
415
*/
416
416
private _setActiveInDefaultMode ( delta : - 1 | 1 ) : void {
417
- this . _setActiveItemByIndex ( this . _activeItemIndex + delta , delta ) ;
417
+ this . _setActiveItemByIndex ( this . _activeItemIndex ( ) + delta , delta ) ;
418
418
}
419
419
420
420
/**
@@ -456,8 +456,8 @@ export class ListKeyManager<T extends ListKeyManagerOption> {
456
456
if ( activeItem ) {
457
457
const newIndex = newItems . indexOf ( activeItem ) ;
458
458
459
- if ( newIndex > - 1 && newIndex !== this . _activeItemIndex ) {
460
- this . _activeItemIndex = newIndex ;
459
+ if ( newIndex > - 1 && newIndex !== this . _activeItemIndex ( ) ) {
460
+ this . _activeItemIndex . set ( newIndex ) ;
461
461
this . _typeahead ?. setCurrentSelectedItemIndex ( newIndex ) ;
462
462
}
463
463
}
0 commit comments