Merge branch 'main' into avm99963-monorail
Merged commit 4137ed7879acadbf891e8c471108acb874dae886.
GitOrigin-RevId: b6100ffc5b1da355a35f37b13fcaaf746ee8b307
diff --git a/static_src/react/ReactAutocomplete.tsx b/static_src/react/ReactAutocomplete.tsx
index 27fdc32..60284a8 100644
--- a/static_src/react/ReactAutocomplete.tsx
+++ b/static_src/react/ReactAutocomplete.tsx
@@ -86,12 +86,20 @@
if (!inputValue.length) {
return [];
}
+ const prefixMatch = (option: T) => {
+ const label = getOptionLabel(option);
+ return label.substring(0, inputValue.length).toLowerCase() === inputValue.toLowerCase();
+ }
+ const prefixMatchOptions = options.filter(prefixMatch);
+
+ const prefixMatchOptionsSet = new Set(prefixMatchOptions);
const regex = _matchRegex(inputValue);
const predicate = (option: T) => {
- return getOptionLabel(option).match(regex) ||
- getOptionDescription(option).match(regex);
+ return !prefixMatchOptionsSet.has(option) && (getOptionLabel(option).match(regex) ||
+ getOptionDescription(option).match(regex));
}
- return options.filter(predicate).slice(0, MAX_AUTOCOMPLETE_OPTIONS);
+ const matchOptions = options.filter(predicate);
+ return [...prefixMatchOptions, ...matchOptions].slice(0, MAX_AUTOCOMPLETE_OPTIONS);
}
}