This commit is contained in:
Mike Jolley 2023-10-31 15:48:34 +00:00 committed by GitHub
parent 0f9f1cbb92
commit 46063d8fdd
1 changed files with 17 additions and 5 deletions

View File

@ -121,14 +121,26 @@ const Combobox = ( {
// Try to match.
const normalizedFilterValue =
filterValue.toLocaleUpperCase();
const foundOption = options.find(
// Try to find an exact match first using values.
const foundValue = options.find(
( option ) =>
option.label
.toLocaleUpperCase()
.startsWith( normalizedFilterValue ) ||
option.value.toLocaleUpperCase() ===
normalizedFilterValue
normalizedFilterValue
);
if ( foundValue ) {
onChange( foundValue.value );
return;
}
// Fallback to a label match.
const foundOption = options.find( ( option ) =>
option.label
.toLocaleUpperCase()
.startsWith( normalizedFilterValue )
);
if ( foundOption ) {
onChange( foundOption.value );
}