Skip to content

Commit

Permalink
Fix: Autocomplete double click (#2255)
Browse files Browse the repository at this point in the history
  • Loading branch information
thewahome authored Nov 25, 2022
1 parent 48697c2 commit f86a0d2
Showing 1 changed file with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ const AutoComplete = (props: IAutoCompleteProps) => {

const displayAutoCompleteSuggestions = (url: string) => {

setShouldShowSuggestions(false);

const { index } = getLastDelimiterInUrl(url);
const { previous: preceedingText } = getSearchText(url, index!);
const { previous: preceedingText, searchText: searchTerm } = getSearchText(url, index!);
const shouldSuggestVersions = preceedingText === GRAPH_URL + '/';

setShouldShowSuggestions(false);

let theSuggestions: string[] = [];
if (shouldSuggestVersions) {
theSuggestions = GRAPH_API_VERSIONS;
Expand All @@ -184,16 +184,19 @@ const AutoComplete = (props: IAutoCompleteProps) => {
theSuggestions = getSuggestions(url, autoCompleteOptions);
}

if (theSuggestions.length > 0) {
const filtered = (searchText) ? getFilteredSuggestions(searchText, theSuggestions) : theSuggestions;
if (filtered.length > 0) {
setSuggestions(filtered);
setShouldShowSuggestions(true);
}
} else {
setShouldShowSuggestions(false);
if (theSuggestions.length === 0) {
return;
}

const filtered = (searchText) ? getFilteredSuggestions(searchText, theSuggestions) : theSuggestions;
if (filtered.length > 0) {
setSuggestions(filtered);
setShouldShowSuggestions(true);
}

if (filtered.length === 1 && filtered[0] === searchTerm) {
setShouldShowSuggestions(false);
}
}

const trackSuggestionSelectionEvent = (suggestion: string) => {
Expand Down

0 comments on commit f86a0d2

Please sign in to comment.