-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Dropdown multi option removed update value. #1970
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
94b7a91
Add test dropdown remove options.
T4rk1n 08fd630
Run black on components from main npm run format.
T4rk1n 6422036
Refactor Dropdown & Fix multi option removed.
T4rk1n 0801dad
Handle case where multi is true and value is not an array.
T4rk1n 136f120
Update components/dash-core-components/src/fragments/Dropdown.react.js
T4rk1n 7eaa9be
Fix Dropdown comma in value. #1908
T4rk1n 8cc4eac
Update changelog for 1970.
T4rk1n 5ce9455
Add private::format.dcc root command.
T4rk1n ed5942e
Replace omit with pick
T4rk1n File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,22 +2,22 @@ | |
import json | ||
from setuptools import setup | ||
|
||
with open('package.json') as f: | ||
with open("package.json") as f: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can delete Anyway I won't make you do this now, but I'm reminded of it after seeing this file being edited. |
||
package = json.load(f) | ||
|
||
package_name = str(package["name"].replace(" ", "_").replace("-", "_")) | ||
|
||
setup( | ||
name='dash_html_components', | ||
name="dash_html_components", | ||
version=package["version"], | ||
author=package['author'], | ||
author_email='chris@plotly.com', | ||
author=package["author"], | ||
author_email="chris@plotly.com", | ||
packages=[package_name], | ||
url='https://github.com/plotly/dash-html-components', | ||
url="https://github.com/plotly/dash-html-components", | ||
include_package_data=True, | ||
license=package['license'], | ||
description=package['description'] if 'description' in package else package_name, | ||
long_description=io.open('README.md', encoding='utf-8').read(), | ||
long_description_content_type='text/markdown', | ||
install_requires=[] | ||
license=package["license"], | ||
description=package["description"] if "description" in package else package_name, | ||
long_description=io.open("README.md", encoding="utf-8").read(), | ||
long_description_content_type="text/markdown", | ||
install_requires=[], | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ha, we should include this file in our linting / formatting runs. If we did, the new linter would ask for this to become an f-string ;)