Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Comboboxes should match against values before looking at labels #11410

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions assets/js/base/components/combobox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down
Loading