delegates helper in the list controller

This commit is contained in:
vdegenne 2024-09-05 12:12:45 +02:00
parent c3a5c0e7b3
commit 470710b2ad
2 changed files with 12 additions and 8 deletions

View File

@ -138,6 +138,14 @@ export class ListController<Item extends ListItem> {
return items; return items;
} }
/**
* Retrieves the first activated item of the array of items regarding
* controller's configuration.
*/
get activeItem() {
return getActiveItem(this.items, this.isActivatable);
}
/** /**
* Handles keyboard navigation. Should be bound to the node that will act as * Handles keyboard navigation. Should be bound to the node that will act as
* the List. * the List.

View File

@ -8,11 +8,7 @@ import {html, isServer, LitElement} from 'lit';
import {queryAssignedElements} from 'lit/decorators.js'; import {queryAssignedElements} from 'lit/decorators.js';
import {ListController, NavigableKeys} from './list-controller.js'; import {ListController, NavigableKeys} from './list-controller.js';
import { import {ListItem as SharedListItem} from './list-navigation-helpers.js';
getActiveItem,
type ItemRecord,
ListItem as SharedListItem,
} from './list-navigation-helpers.js';
const NAVIGABLE_KEY_SET = new Set<string>(Object.values(NavigableKeys)); const NAVIGABLE_KEY_SET = new Set<string>(Object.values(NavigableKeys));
@ -96,12 +92,12 @@ export class List extends LitElement {
} }
/** /**
* Retrieves the first activated item of a given array of items. * Retrieves the first activated item of the array of items.
* *
* @return A record of the first activated item including the item and the * @return A record of the first activated item including the item and the
* index of the item or `null` if none are activated. * index of the item or `null` if none are activated.
*/ */
get activeItem(): ItemRecord<ListItem> | null { get activeItem() {
return getActiveItem(this.items); return this.listController.activeItem;
} }
} }