Fix typeahead search logic when repeating a letter

Fixes #35

This ports 186a4cfcef
This commit is contained in:
Ryan Gossiaux
2022-01-21 17:06:51 -08:00
parent bc809ef590
commit 5e795d2d4f
4 changed files with 102 additions and 6 deletions

View File

@@ -139,14 +139,22 @@
searchQuery += value.toLowerCase();
let match = options.findIndex(
let reorderedOptions =
activeOptionIndex !== null
? options
.slice(activeOptionIndex + 1)
.concat(options.slice(0, activeOptionIndex + 1))
: options;
let matchingOption = reorderedOptions.find(
(option) =>
!option.dataRef.disabled &&
option.dataRef.textValue.startsWith(searchQuery)
);
if (match === -1 || match === activeOptionIndex) return;
activeOptionIndex = match;
let matchIdx = matchingOption ? options.indexOf(matchingOption) : -1;
if (matchIdx === -1 || matchIdx === activeOptionIndex) return;
activeOptionIndex = matchIdx;
},
clearSearch() {
if (disabled) return;