Skip to content

Commit b7f550f

Browse files
committed
Fix dropdown
1 parent ba5e2ab commit b7f550f

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

components/dash-core-components/src/fragments/Dropdown.react.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {isNil, pluck, without, pick} from 'ramda';
1+
import {isNil, pluck, without, pick, isEmpty} from 'ramda';
22
import React, {useState, useCallback, useEffect, useMemo, useRef} from 'react';
33
import ReactDropdown from 'react-virtualized-select';
44
import createFilterOptions from 'react-select-fast-filter-options';
@@ -125,7 +125,8 @@ const Dropdown = props => {
125125
!search_value &&
126126
!isNil(sanitizedOptions) &&
127127
optionsCheck !== sanitizedOptions &&
128-
!isNil(value)
128+
!isNil(value) &&
129+
!isEmpty(value)
129130
) {
130131
const values = sanitizedOptions.map(option => option.value);
131132
if (multi && Array.isArray(value)) {

components/dash-core-components/tests/integration/dropdown/test_remove_option.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import pytest
44

5-
from dash import Dash, html, dcc, Output, Input, State
5+
from dash import Dash, html, dcc, Output, Input, State, Patch
66
from dash.exceptions import PreventUpdate
77

8+
from selenium.webdriver.common.keys import Keys
89

910
sample_dropdown_options = [
1011
{"label": "New York City", "value": "NYC"},
@@ -147,3 +148,44 @@ def print_value(n_clicks, options, value):
147148
btn.click()
148149
dash_dcc.wait_for_text_to_equal("#value-output", '["NYC"]')
149150
dash_dcc.wait_for_text_to_equal("#options-output", '["MTL", "NYC"]')
151+
152+
153+
def test_ddro004_empty_string_not_updated(dash_dcc):
154+
# The value should stay as empty string and not null.
155+
app = Dash()
156+
app.layout = html.Div(
157+
[
158+
dcc.Dropdown(["a", "b", "c"], value="", id="drop"),
159+
html.Div(id="output"),
160+
dcc.Store(data={"count": 0}, id="count"),
161+
html.Div(id="count-output"),
162+
]
163+
)
164+
165+
@app.callback(
166+
Output("output", "children"),
167+
Output("count", "data"),
168+
Input("drop", "value"),
169+
)
170+
def on_value(value):
171+
count = Patch()
172+
count.count += 1
173+
if value is None:
174+
return "Value is none", count
175+
return f"Value={value}", count
176+
177+
app.clientside_callback(
178+
"data => data.count", Output("count-output", "children"), Input("count", "data")
179+
)
180+
181+
dash_dcc.start_server(app)
182+
dash_dcc.wait_for_text_to_equal("#output", "Value=")
183+
184+
dash_dcc.wait_for_text_to_equal("#count-output", "1")
185+
186+
select_input = dash_dcc.find_element("#drop input")
187+
select_input.send_keys("a")
188+
select_input.send_keys(Keys.ENTER)
189+
190+
dash_dcc.wait_for_text_to_equal("#output", "Value=a")
191+
dash_dcc.wait_for_text_to_equal("#count-output", "2")

0 commit comments

Comments
 (0)