Skip to content

Commit

Permalink
fix: #7527, Dropdown: Editable Dropdown search not working as expected (
Browse files Browse the repository at this point in the history
#7528)

Co-authored-by: ANTONA09 <[email protected]>
  • Loading branch information
akshayaqburst and ANTONA09 authored Dec 26, 2024
1 parent 63c6c34 commit fb4d9f1
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion components/lib/dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,12 +588,24 @@ export const Dropdown = React.memo(
return isOptionDisabled(option) ? findPrevOption(i) : option;
};

const findInArray = (visibleOptions, searchText) => {
if (!searchText || !visibleOptions?.length) return -1;

const normalizedSearch = searchText.toLocaleLowerCase();

const exactMatch = visibleOptions.findIndex((item) => getOptionLabel(item).toLocaleLowerCase() === normalizedSearch);

if (exactMatch !== -1) return exactMatch;

return visibleOptions.findIndex((item) => getOptionLabel(item).toLocaleLowerCase().startsWith(normalizedSearch));
};

const onEditableInputChange = (event) => {
!overlayVisibleState && show();
let searchIndex = null;

if (event.target.value && visibleOptions) {
searchIndex = visibleOptions.findIndex((item) => getOptionLabel(item).toLocaleLowerCase().startsWith(event.target.value.toLocaleLowerCase()));
searchIndex = findInArray(visibleOptions, event.target.value);
}

setFocusedOptionIndex(searchIndex);
Expand Down

0 comments on commit fb4d9f1

Please sign in to comment.