plotly / dash

Data Apps & Dashboards for Python. No JavaScript Required.
https://plotly.com/dash
MIT License
21.16k stars 2.04k forks source link

dcc.Dropdown clearing set selected value to option with value="" #2054

Open HenrikSpiegel opened 2 years ago

HenrikSpiegel commented 2 years ago

Describe your context Please provide us your environment, so we can easily reproduce the issue.

Describe the bug

When clearing a dropdown with multi=True it will not clear if there is an option with value="". Instead when attempting to clear it will show that that an option with value="" has been selected.

Furthermore, if an option with value="" has been selected then all other options where value="" disappears.

I suspect it is related to changes in !1970 As this behavior is new and it appears the 1970 fix changes setting the value of dropdowns.

Expected behavior

When deleting the last option one would expect the dropdown to clear and not select value="" option.

Furthermore, it is not appropriate that options that share values are hidden when selected.

Screenshots

Component:

dcc.Dropdown(
  multi=True,
  clearable=True,
  options = [
      {'label': 'Non-empty-option', 'value':'value'},
      {'label': 'empty-option-disabled', 'value':'', 'disabled':True},
      {'label': 'empty-option', 'value':''}
  ]
  )

On initial load: image

Select option with a value='value' image

Clear the options: Note: Clicking either cross does nothing, furthermore, the option labeled 'empty-option' has disappeared from list. image

We can then select the value='value' option. we still can't see the 'empty-option' item. image

Deselect 'empty-option-disabled': image

Both options with value="" have returned.

nickmelnikov82 commented 2 years ago

Here is a similar problem #1647. The "value" attribute must be unique.