Skip to content

Commit

Permalink
Merge pull request #2104 from plotly/2099-dropdown-search
Browse files Browse the repository at this point in the history
2099 dropdown search
  • Loading branch information
T4rk1n authored Jun 28, 2022
2 parents ac7b37d + f2d02f6 commit d558862
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).

- [#2098](https://github.com/plotly/dash/pull/2098) Accept HTTP code 400 as well as 401 for JWT expiry
- [#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.
- [#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.

## [2.5.1] - 2022-06-13

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const Dropdown = props => {
const {
id,
clearable,
searchable,
multi,
options,
setProps,
Expand Down Expand Up @@ -86,6 +87,7 @@ const Dropdown = props => {

useEffect(() => {
if (
!searchable &&
!isNil(sanitizedOptions) &&
optionsCheck !== sanitizedOptions &&
!isNil(value)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import time

from selenium.webdriver.common.keys import Keys

from dash import Dash, Input, Output, dcc, html
from dash.exceptions import PreventUpdate

Expand Down Expand Up @@ -81,3 +85,45 @@ def test_dddo003_value_no_options(dash_dcc):
dash_dcc.start_server(app)
assert dash_dcc.get_logs() == []
dash_dcc.wait_for_element("#dropdown")


def test_dddo004_dynamic_value_search(dash_dcc):
# Bug clear the search input while typing
# https://github.com/plotly/dash/issues/2099

options = [
{"label": "aa1", "value": "aa1"},
{"label": "aa2", "value": "aa2"},
{"label": "aa3", "value": "aa3"},
{"label": "best value", "value": "bb1"},
{"label": "better value", "value": "bb2"},
{"label": "bye", "value": "bb3"},
]

app = Dash(__name__)
app.layout = html.Div(
[
html.Div(
["Single dynamic Dropdown", dcc.Dropdown(id="dropdown")],
style={"width": 200, "marginLeft": 20, "marginTop": 20},
),
]
)

@app.callback(Output("dropdown", "options"), Input("dropdown", "search_value"))
def update_options(search_value):
if not search_value:
raise PreventUpdate
return [o for o in options if search_value in o["label"]]

dash_dcc.start_server(app)

input_ = dash_dcc.find_element("#dropdown input")

input_.send_keys("aa1")
input_.send_keys(Keys.ENTER)

input_.send_keys("b")

time.sleep(1)
assert input_.get_attribute("value") == "b"
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def test_ddro001_remove_option_single(dash_dcc):
dcc.Dropdown(
options=dropdown_options,
value=value,
searchable=False,
id="dropdown",
),
html.Button("Remove option", id="remove"),
Expand Down Expand Up @@ -61,6 +62,7 @@ def test_ddro002_remove_option_multi(dash_dcc):
value=value,
multi=True,
id="dropdown",
searchable=False,
),
html.Button("Remove option", id="remove"),
html.Div(id="value-output"),
Expand Down

0 comments on commit d558862

Please # to comment.