From 3a71352f2a8f21302b868e9f26032f6dcb1589af Mon Sep 17 00:00:00 2001 From: vdegenne Date: Thu, 5 Sep 2024 11:24:21 +0200 Subject: [PATCH 1/6] feat(list): add activatedItem getter --- list/internal/list.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/list/internal/list.ts b/list/internal/list.ts index c5ec9dbb9f..e6cd66f288 100644 --- a/list/internal/list.ts +++ b/list/internal/list.ts @@ -90,4 +90,13 @@ export class List extends LitElement { activatePreviousItem(): ListItem | null { return this.listController.activatePreviousItem(); } + + /** + * Returns the activated item in the list. + * + * @return The activated list item or `null` if there are no items. + */ + get activatedItem(): ListItem | null { + return this.items.find((i: ListItem) => i.tabIndex === 0); + } } From f23e6eb21c1b580b046579429afbdb7ffcc6601e Mon Sep 17 00:00:00 2001 From: vdegenne Date: Thu, 5 Sep 2024 11:46:47 +0200 Subject: [PATCH 2/6] use navigation list helper --- list/internal/list.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/list/internal/list.ts b/list/internal/list.ts index e6cd66f288..21d910e7a0 100644 --- a/list/internal/list.ts +++ b/list/internal/list.ts @@ -8,7 +8,7 @@ import {html, isServer, LitElement} from 'lit'; import {queryAssignedElements} from 'lit/decorators.js'; import {ListController, NavigableKeys} from './list-controller.js'; -import {ListItem as SharedListItem} from './list-navigation-helpers.js'; +import {getActiveItem, ItemRecord, ListItem as SharedListItem} from './list-navigation-helpers.js'; const NAVIGABLE_KEY_SET = new Set(Object.values(NavigableKeys)); @@ -92,11 +92,12 @@ export class List extends LitElement { } /** - * Returns the activated item in the list. + * Retrieves the first activated item of a given array of items. * - * @return The activated list item or `null` if there are no items. + * @return A record of the first activated item including the item and the + * index of the item or `null` if none are activated. */ - get activatedItem(): ListItem | null { - return this.items.find((i: ListItem) => i.tabIndex === 0); + get activeItem(): ItemRecord | null { + return getActiveItem(this.items) } } From 04f978676f8d427f89615c55cb4ef38062c39606 Mon Sep 17 00:00:00 2001 From: vdegenne Date: Thu, 5 Sep 2024 11:48:07 +0200 Subject: [PATCH 3/6] add type keyword on ItemRecord --- list/internal/list.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/list/internal/list.ts b/list/internal/list.ts index 21d910e7a0..aca796b8e1 100644 --- a/list/internal/list.ts +++ b/list/internal/list.ts @@ -8,7 +8,7 @@ import {html, isServer, LitElement} from 'lit'; import {queryAssignedElements} from 'lit/decorators.js'; import {ListController, NavigableKeys} from './list-controller.js'; -import {getActiveItem, ItemRecord, ListItem as SharedListItem} from './list-navigation-helpers.js'; +import {getActiveItem, type ItemRecord, ListItem as SharedListItem} from './list-navigation-helpers.js'; const NAVIGABLE_KEY_SET = new Set(Object.values(NavigableKeys)); From 888b0cf5c981e5a597dfd0405c02d89e672d7b2d Mon Sep 17 00:00:00 2001 From: vdegenne Date: Thu, 5 Sep 2024 11:49:32 +0200 Subject: [PATCH 4/6] format imports for readability --- list/internal/list.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/list/internal/list.ts b/list/internal/list.ts index aca796b8e1..2db1ad2544 100644 --- a/list/internal/list.ts +++ b/list/internal/list.ts @@ -8,7 +8,11 @@ import {html, isServer, LitElement} from 'lit'; import {queryAssignedElements} from 'lit/decorators.js'; import {ListController, NavigableKeys} from './list-controller.js'; -import {getActiveItem, type ItemRecord, ListItem as SharedListItem} from './list-navigation-helpers.js'; +import { + getActiveItem, + type ItemRecord, + ListItem as SharedListItem, +} from './list-navigation-helpers.js'; const NAVIGABLE_KEY_SET = new Set(Object.values(NavigableKeys)); From c3a5c0e7b33ac0f9c64bcc46f0ba5a09cb4fde01 Mon Sep 17 00:00:00 2001 From: vdegenne Date: Thu, 5 Sep 2024 11:50:59 +0200 Subject: [PATCH 5/6] typo --- list/internal/list.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/list/internal/list.ts b/list/internal/list.ts index 2db1ad2544..a7e2810902 100644 --- a/list/internal/list.ts +++ b/list/internal/list.ts @@ -102,6 +102,6 @@ export class List extends LitElement { * index of the item or `null` if none are activated. */ get activeItem(): ItemRecord | null { - return getActiveItem(this.items) + return getActiveItem(this.items); } } From 470710b2ad01f3b8e7f08eba9cb35a9a96c8489e Mon Sep 17 00:00:00 2001 From: vdegenne Date: Thu, 5 Sep 2024 12:12:45 +0200 Subject: [PATCH 6/6] delegates helper in the list controller --- list/internal/list-controller.ts | 8 ++++++++ list/internal/list.ts | 12 ++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/list/internal/list-controller.ts b/list/internal/list-controller.ts index 707ab2fb05..ee0b420b7a 100644 --- a/list/internal/list-controller.ts +++ b/list/internal/list-controller.ts @@ -138,6 +138,14 @@ export class ListController { 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 * the List. diff --git a/list/internal/list.ts b/list/internal/list.ts index a7e2810902..4788a545f1 100644 --- a/list/internal/list.ts +++ b/list/internal/list.ts @@ -8,11 +8,7 @@ import {html, isServer, LitElement} from 'lit'; import {queryAssignedElements} from 'lit/decorators.js'; import {ListController, NavigableKeys} from './list-controller.js'; -import { - getActiveItem, - type ItemRecord, - ListItem as SharedListItem, -} from './list-navigation-helpers.js'; +import {ListItem as SharedListItem} from './list-navigation-helpers.js'; const NAVIGABLE_KEY_SET = new Set(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 * index of the item or `null` if none are activated. */ - get activeItem(): ItemRecord | null { - return getActiveItem(this.items); + get activeItem() { + return this.listController.activeItem; } }