ignore fetched suggestions if input already cleared (#17419)

This commit is contained in:
Suzanne Aitchison 2022-04-25 16:03:36 +01:00 committed by GitHub
parent a514ca39b8
commit e6c4e3ba2e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -303,6 +303,12 @@ export const MultiSelectAutocomplete = ({
}
const results = await fetchSuggestions(value);
// It could be that while waiting on the network fetch, the user has already made a selection or otherwise cleared the input
if (inputRef.current.value === '') {
return;
}
// If no results, display current search term as an option
if (results.length === 0 && value !== '') {
results.push({ name: value });