Skip to content

Commit

Permalink
front: Fix Dynamic Update of Autocomplete Dropdown in Search Component.
Browse files Browse the repository at this point in the history
Fixed an issue where the autocomplete dropdown in the Search component was not
updating correctly with user input. The dropdown now dynamically updates with
search results as the user types, reflecting successful backend API responses.
This fix involved disabling the built-in filtering of the Autocomplete
component, as per MUI documentation guidelines, to allow for better handling of
dynamic search results.

Issue: #171

Signed-off-by: Nikolay Martyanov <[email protected]>
  • Loading branch information
OhmSpectator committed Dec 21, 2023
1 parent 19d952e commit 5bba937
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions frontend/src/components/Search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ function Search() {
<Autocomplete
id="search-autocomplete"
options={searchResults.length > 0 ? formatNames(searchResults) : [inputValue]}
filterOptions={(x) => x}
getOptionLabel={(option) => {
if (option && typeof option === 'object' && option.name) {
return option.segment ? `${option.name} (${option.segment})` : option.name;
Expand Down Expand Up @@ -159,11 +160,9 @@ function Search() {
setIsDropdownOpen(false);
return;
}
// find the region with the matching name
const matchingRegion = searchResults.find((region) => region.name === newInputValue);
setInputValue(matchingRegion);
setInputValue(newInputValue);
setSearchTerm({
name: matchingRegion ? matchingRegion.name : newInputValue,
name: newInputValue,
force: false,
});
}}
Expand Down

0 comments on commit 5bba937

Please sign in to comment.