Skip to content

Commit 1de694b

Browse files
committed
fixup! refactor(aria/toolbar): large rework of toolbar internals
1 parent faa7b5f commit 1de694b

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/aria/private/behaviors/list-navigation/list-navigation.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,29 @@ export class ListNavigation<T extends ListNavigationItem> {
5555

5656
/** Navigates to the first item in the list. */
5757
first(opts?: {focusElement?: boolean}): boolean {
58-
const item = this.inputs.items().find(i => this.inputs.focusManager.isFocusable(i));
58+
const item = this.getFirstFocusableItem();
5959
return item ? this.goto(item, opts) : false;
6060
}
6161

6262
/** Navigates to the last item in the list. */
6363
last(opts?: {focusElement?: boolean}): boolean {
64-
const items = this.inputs.items();
64+
const item = this.getLastFocusableItem();
65+
return item ? this.goto(item, opts) : false;
66+
}
67+
68+
/** Gets the first focusable item from the given list of items. */
69+
getFirstFocusableItem(items: T[] = this.inputs.items()): T | undefined {
70+
return items.find(i => this.inputs.focusManager.isFocusable(i));
71+
}
72+
73+
/** Gets the last focusable item from the given list of items. */
74+
getLastFocusableItem(items: T[] = this.inputs.items()): T | undefined {
6575
for (let i = items.length - 1; i >= 0; i--) {
6676
if (this.inputs.focusManager.isFocusable(items[i])) {
67-
return this.goto(items[i], opts);
77+
return items[i];
6878
}
6979
}
70-
return false;
80+
return;
7181
}
7282

7383
/** Advances to the next or previous focusable item in the list based on the given delta. */

src/aria/private/behaviors/list/list.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ export class List<T extends ListItem<V>, V> {
161161
}
162162

163163
/** Deselects the currently active item in the list. */
164-
deselect() {
165-
this.selectionBehavior.deselect();
164+
deselect(item?: T) {
165+
this.selectionBehavior.deselect(item);
166166
}
167167

168168
/** Deselects all items in the list. */

0 commit comments

Comments
 (0)