Fixed that previous value, not current value has been taken to fetch suggestions
This commit is contained in:
parent
414295adbc
commit
335c5923d6
|
@ -43,13 +43,13 @@ fun <T> AutocompleteTextField(
|
|||
val coroutineScope = rememberCoroutineScope()
|
||||
|
||||
|
||||
fun fetchSuggestionsAsync() {
|
||||
fun fetchSuggestionsAsync(query: String) {
|
||||
suggestionsFetchJob?.cancel()
|
||||
|
||||
suggestionsFetchJob = coroutineScope.launch {
|
||||
isLoading = true
|
||||
|
||||
suggestions = fetchSuggestions(value)
|
||||
suggestions = fetchSuggestions(query)
|
||||
|
||||
isLoading = false
|
||||
if (expanded == false && suggestions.isNotEmpty()) {
|
||||
|
@ -67,7 +67,7 @@ fun <T> AutocompleteTextField(
|
|||
onEnteredTextChanged(query)
|
||||
|
||||
if (query.length >= minTextLengthForSearch) {
|
||||
fetchSuggestionsAsync()
|
||||
fetchSuggestionsAsync(query)
|
||||
} else {
|
||||
suggestions = emptyList()
|
||||
expanded = false
|
||||
|
@ -75,7 +75,7 @@ fun <T> AutocompleteTextField(
|
|||
},
|
||||
modifier = Modifier.fillMaxWidth().focusRequester(textFieldFocus).onFocusChanged { focusState ->
|
||||
if (focusState.isFocused && minTextLengthForSearch == 0) {
|
||||
fetchSuggestionsAsync()
|
||||
fetchSuggestionsAsync(value)
|
||||
}
|
||||
},
|
||||
label = { Text(label) },
|
||||
|
|
Loading…
Reference in New Issue