Skip to content

Commit c51c125

Browse files
committed
refactor(multiple): improve aria ListTypeahead._getItem (#32579)
(cherry picked from commit c27b1b4)
1 parent 7778c7a commit c51c125

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,22 @@ export class ListTypeahead<T extends ListTypeaheadItem> {
8383
* current query starting from the the current anchor index.
8484
*/
8585
private _getItem() {
86-
let items = this.focusManager.inputs.items();
87-
const after = items.slice(this._startIndex()! + 1);
88-
const before = items.slice(0, this._startIndex()!);
89-
items = after.concat(before);
90-
items.push(this.inputs.items()[this._startIndex()!]);
91-
92-
const focusableItems = [];
93-
for (const item of items) {
94-
if (this.focusManager.isFocusable(item)) {
95-
focusableItems.push(item);
86+
const items = this.focusManager.inputs.items();
87+
const itemCount = items.length;
88+
const startIndex = this._startIndex()!;
89+
90+
for (let i = 0; i < itemCount; i++) {
91+
const index = (startIndex + 1 + i) % itemCount;
92+
const item = items[index];
93+
94+
if (
95+
this.focusManager.isFocusable(item) &&
96+
item.searchTerm().toLowerCase().startsWith(this._query())
97+
) {
98+
return item;
9699
}
97100
}
98101

99-
return focusableItems.find(i => i.searchTerm().toLowerCase().startsWith(this._query()));
102+
return undefined;
100103
}
101104
}

0 commit comments

Comments
 (0)