Closed therladbsgh closed 3 years ago
Thanks for your contribution.
Just one question before merging the request.
Can you give an example where the search results will defer when the only whitespace is entered at the end? If the result is always the same whether you enter the whitespace at the end or not, I don't see the reason we should put 'prevTermSearch' or even the 'autocompleteOnTrailingWhitespace' parameter.
Would be wonderful to give an example to package users in which scenario they can set 'autocompleteOnTrailingWhitespace' to true. ;)
Not entirely sure what the question is, but I can provide a few example cases:
Case 1. User enters "Uber hq" without the timeout triggering inbetween.
autocompleteOnTrailingWhitespace
.Case 2. User enters "Uber hq " without the timeout triggering inbetween.
autocompleteOnTrailingWhitespace
is false, the timeout is cancelled and there is no search performed.autocompleteOnTrailingWhitespace
is true, the timeout is not cancelled and search is performed for "uber hq".Case 3. User enters "Uber", enters timeout (search results), then adds a space ("uber ") then waits.
autocompleteOnTrailingWhitespace
is false, then the search is performed for the first timeout, and search is not performed for the second space.autocompleteOnTrailingWhitespace
is true, then the search is performed for the first timeout, and search is not performed for the second space as the trimmed version is the same as the trimmed version of the previous searched term "uber". (Without prevTermSearch
, we would do another search which is unnecessary.)Case 4. User enters "Uber", enters timeout, then adds another term ("Uber hq "), then waits.
autocompleteOnTrailingWhitespace
is false, then the search is performed for the first timeout, and not performed for the second term.autocompleteOnTrailingWhitespace
is true, then the search is performed for the first timeout, and also performed for the second term, as 1) we ignore the whitespace, and 2) the trimmed term is different from the trimmed previous search (implying the text is semantically different from what we have searched before.)In essence autocompleteOnTrailingWhitespace
removes any effect whitespace will have on autocomplete search while keeping the same amount of API calls. As you said before, from a UX standpoint this makes more intuitive sense.
Fair enough!
Thanks for the explanation and example cases, @therladbsgh. It is more than enough to provide information on how to use the new parameter.
I will merge the request and include this to the next update of the package.
In reference to issue #54
Adds a
autocompleteOnTrailingWhitespace
parameter to PlacePicker to allow autocomplete to run even on whitespace. This defaults to false for backwards compatibility.To reduce unnecessary API calls, a
prevTermSearch
is introduced in SearchProvider to compare the current term in the search bar with what is previously searched; if the only difference is whitespace, the API is not called.