Autocomplete onBlur clears the selected value
Bug report 🐞
Version & Environment
- Version of browser:
- Chrome v92.0.4515.159
- Brave v1.29.77
- Version of
geist-ui/react: v2.2.0
Expected Behaviour
The behavior I expect is to have the value of the Autocomplete remain in place in the event that a user clicks away from the Autocomplete without selecting a new item.
Actual results (or Errors)
I got an error: There are no errors thrown in this case. The autocomplete simply is not persisting the previously selected value, when you click away without selecting a new option.
<AutoComplete
initialValue={value}
value={value}
width={width || '100%'}
placeholder="Search by zone name"
disableFreeSolo
clearable
options={listOptions}
onSearch={handleSearch}
onSelect={handleSelect}
scale={1}>
<AutoComplete.Empty>
<span>No Options...</span>
</AutoComplete.Empty>
</AutoComplete>
I've posted a video of this issue in the next comment 👍
Additional Notes: We are not controlling the onBlur event, and we did notice that when we add a onBlur handler to the AutoComplete component it no longer closes the menu upon clicking away from the Autocomplete.
https://user-images.githubusercontent.com/9354827/132398894-3ca76a50-ff66-48fb-b7ed-b5d4fcaeb5b0.mov
Hi @stormy251, is the Test option the initial value? Do you have a value string for each option?
Hey @ofekashery,
Thank you for your response, I have double checked, that each item in the options array contains a non empty string value. In this case the Test option is the initial value correct 👍 .
If I had to guess where this problem/potential bug exists, I would say there is some sort of onBlur internal to the AutoComplete, that when I provide disableFreeSolo & clearable properties, it complicates the onBlur, and results in clearing the currently set value.
This is a feature of AutoComplete. When you turn on the disableFreeSolo, you can only enter values from the list.
The reason for this problem is that the value or initialValue of component AutoComplete is not exactly equal to the one provided in options.value.
I tested this again manually and if value / initialValue and option.value are equal, then onBlur does not remove the value of the input box in disableFreeSole & clearable mode.
This issue was closed because it was not active for a long time, please reopen when there are updates.