Skip to content

Commit d558862

Browse files
authored
Merge pull request #2104 from plotly/2099-dropdown-search
2099 dropdown search
2 parents ac7b37d + f2d02f6 commit d558862

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
88

99
- [#2098](https://github.com/plotly/dash/pull/2098) Accept HTTP code 400 as well as 401 for JWT expiry
1010
- [#2097](https://github.com/plotly/dash/pull/2097) Fix bug [#2095](https://github.com/plotly/dash/issues/2095) with TypeScript compiler and `React.FC` empty valueDeclaration error & support empty props components.
11+
- [#2104](https://github.com/plotly/dash/pull/2104) Fix bug [#2099](https://github.com/plotly/dash/issues/2099) with Dropdown clearing search value when a value is selected.
1112

1213
## [2.5.1] - 2022-06-13
1314

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

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const Dropdown = props => {
3737
const {
3838
id,
3939
clearable,
40+
searchable,
4041
multi,
4142
options,
4243
setProps,
@@ -86,6 +87,7 @@ const Dropdown = props => {
8687

8788
useEffect(() => {
8889
if (
90+
!searchable &&
8991
!isNil(sanitizedOptions) &&
9092
optionsCheck !== sanitizedOptions &&
9193
!isNil(value)

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

+46
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import time
2+
3+
from selenium.webdriver.common.keys import Keys
4+
15
from dash import Dash, Input, Output, dcc, html
26
from dash.exceptions import PreventUpdate
37

@@ -81,3 +85,45 @@ def test_dddo003_value_no_options(dash_dcc):
8185
dash_dcc.start_server(app)
8286
assert dash_dcc.get_logs() == []
8387
dash_dcc.wait_for_element("#dropdown")
88+
89+
90+
def test_dddo004_dynamic_value_search(dash_dcc):
91+
# Bug clear the search input while typing
92+
# https://github.com/plotly/dash/issues/2099
93+
94+
options = [
95+
{"label": "aa1", "value": "aa1"},
96+
{"label": "aa2", "value": "aa2"},
97+
{"label": "aa3", "value": "aa3"},
98+
{"label": "best value", "value": "bb1"},
99+
{"label": "better value", "value": "bb2"},
100+
{"label": "bye", "value": "bb3"},
101+
]
102+
103+
app = Dash(__name__)
104+
app.layout = html.Div(
105+
[
106+
html.Div(
107+
["Single dynamic Dropdown", dcc.Dropdown(id="dropdown")],
108+
style={"width": 200, "marginLeft": 20, "marginTop": 20},
109+
),
110+
]
111+
)
112+
113+
@app.callback(Output("dropdown", "options"), Input("dropdown", "search_value"))
114+
def update_options(search_value):
115+
if not search_value:
116+
raise PreventUpdate
117+
return [o for o in options if search_value in o["label"]]
118+
119+
dash_dcc.start_server(app)
120+
121+
input_ = dash_dcc.find_element("#dropdown input")
122+
123+
input_.send_keys("aa1")
124+
input_.send_keys(Keys.ENTER)
125+
126+
input_.send_keys("b")
127+
128+
time.sleep(1)
129+
assert input_.get_attribute("value") == "b"

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

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def test_ddro001_remove_option_single(dash_dcc):
2222
dcc.Dropdown(
2323
options=dropdown_options,
2424
value=value,
25+
searchable=False,
2526
id="dropdown",
2627
),
2728
html.Button("Remove option", id="remove"),
@@ -61,6 +62,7 @@ def test_ddro002_remove_option_multi(dash_dcc):
6162
value=value,
6263
multi=True,
6364
id="dropdown",
65+
searchable=False,
6466
),
6567
html.Button("Remove option", id="remove"),
6668
html.Div(id="value-output"),

0 commit comments

Comments
 (0)