Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(list): add activeItem getter #5704

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions list/internal/list-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ export class ListController<Item extends ListItem> {
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.
Expand Down
10 changes: 10 additions & 0 deletions list/internal/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,14 @@ export class List extends LitElement {
activatePreviousItem(): ListItem | null {
return this.listController.activatePreviousItem();
}

/**
* Retrieves the first activated item of the array of items.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "array of items, or null." to be more explicit

*
* @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() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this above next to the other get items() property and add @export to the jsdoc?

return this.listController.activeItem;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should expose the {item, index} object that the controller uses. Instead, I would suggest separate activeItem and activeItemIndex properties, like how tabs work.

}
}