geist-ui icon indicating copy to clipboard operation
geist-ui copied to clipboard

Autocomplete onBlur clears the selected value

Open stormy251 opened this issue 5 years ago • 6 comments

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.

stormy251 avatar Sep 07 '21 19:09 stormy251

https://user-images.githubusercontent.com/9354827/132398894-3ca76a50-ff66-48fb-b7ed-b5d4fcaeb5b0.mov

stormy251 avatar Sep 07 '21 19:09 stormy251

Hi @stormy251, is the Test option the initial value? Do you have a value string for each option?

ofekashery avatar Sep 08 '21 12:09 ofekashery

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.

stormy251 avatar Sep 08 '21 14:09 stormy251

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.

unix avatar Jan 16 '22 09:01 unix

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.

unix avatar Jan 16 '22 09:01 unix

This issue was closed because it was not active for a long time, please reopen when there are updates.

unix avatar Feb 08 '22 05:02 unix