-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1970 from plotly/1868-dropdown-remove-option
Fix Dropdown multi option removed update value.
- Loading branch information
Showing
9 changed files
with
224 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
components/dash-core-components/tests/integration/dropdown/test_remove_option.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import json | ||
|
||
from dash import Dash, html, dcc, Output, Input | ||
from dash.exceptions import PreventUpdate | ||
|
||
|
||
sample_dropdown_options = [ | ||
{"label": "New York City", "value": "NYC"}, | ||
{"label": "Montreal", "value": "MTL"}, | ||
{"label": "San Francisco", "value": "SF"}, | ||
] | ||
|
||
|
||
def test_ddro001_remove_option_single(dash_dcc): | ||
dropdown_options = sample_dropdown_options | ||
|
||
app = Dash(__name__) | ||
value = "SF" | ||
|
||
app.layout = html.Div( | ||
[ | ||
dcc.Dropdown( | ||
options=dropdown_options, | ||
value=value, | ||
id="dropdown", | ||
), | ||
html.Button("Remove option", id="remove"), | ||
html.Div(id="value-output"), | ||
] | ||
) | ||
|
||
@app.callback(Output("dropdown", "options"), [Input("remove", "n_clicks")]) | ||
def on_click(n_clicks): | ||
if not n_clicks: | ||
raise PreventUpdate | ||
return sample_dropdown_options[:-1] | ||
|
||
@app.callback(Output("value-output", "children"), [Input("dropdown", "value")]) | ||
def on_change(val): | ||
if not val: | ||
raise PreventUpdate | ||
return val or "None" | ||
|
||
dash_dcc.start_server(app) | ||
btn = dash_dcc.wait_for_element("#remove") | ||
btn.click() | ||
|
||
dash_dcc.wait_for_text_to_equal("#value-output", "None") | ||
|
||
|
||
def test_ddro002_remove_option_multi(dash_dcc): | ||
dropdown_options = sample_dropdown_options | ||
|
||
app = Dash(__name__) | ||
value = ["MTL", "SF"] | ||
|
||
app.layout = html.Div( | ||
[ | ||
dcc.Dropdown( | ||
options=dropdown_options, | ||
value=value, | ||
multi=True, | ||
id="dropdown", | ||
), | ||
html.Button("Remove option", id="remove"), | ||
html.Div(id="value-output"), | ||
] | ||
) | ||
|
||
@app.callback(Output("dropdown", "options"), [Input("remove", "n_clicks")]) | ||
def on_click(n_clicks): | ||
if not n_clicks: | ||
raise PreventUpdate | ||
return sample_dropdown_options[:-1] | ||
|
||
@app.callback(Output("value-output", "children"), [Input("dropdown", "value")]) | ||
def on_change(val): | ||
return json.dumps(val) | ||
|
||
dash_dcc.start_server(app) | ||
btn = dash_dcc.wait_for_element("#remove") | ||
btn.click() | ||
|
||
dash_dcc.wait_for_text_to_equal("#value-output", '["MTL"]') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.