Skip to content
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

[Feature] Allow Dropdown to Remain Open for multi==True #2821

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ Dropdown.propTypes = {
*/
multi: PropTypes.bool,

/**
* If false and multi=true, then selecting a value will leave the menu open
* to select more values
*/
close_on_select: PropTypes.bool,

/**
* Whether or not the dropdown is "clearable", that is, whether or
* not a small "x" appears on the right of the dropdown that removes
Expand Down Expand Up @@ -229,6 +235,7 @@ Dropdown.defaultProps = {
clearable: true,
disabled: false,
multi: false,
close_on_select: true,
searchable: true,
optionHeight: 35,
maxHeight: 200,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const TOKENIZER = {

const RDProps = [
'multi',
'close_on_select',
'clearable',
'searchable',
'search_value',
Expand All @@ -41,6 +42,7 @@ const Dropdown = props => {
clearable,
searchable,
multi,
close_on_select,
options,
setProps,
style,
Expand Down Expand Up @@ -155,6 +157,7 @@ const Dropdown = props => {
filterOptions={filterOptions}
options={sanitizedOptions}
value={value}
closeOnSelect={multi ? close_on_select : true}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, it would make more sense to not write over the close_on_select prop. If someone were to change multi, the prop would be lost and it would always close.

👍

onChange={onChange}
onInputChange={onInputChange}
backspaceRemoves={clearable}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import json

from dash import Dash, Input, Output, dcc, html
from selenium.webdriver.common.keys import Keys


def test_ddcos001_multi_stay_open(dash_dcc):
app = Dash(__name__)
app.layout = html.Div(
[
dcc.Dropdown(
id="multi-dropdown",
options=[
{"label": "New York City", "value": "NYC"},
{"label": "Montreal", "value": "MTL"},
{"label": "San Francisco", "value": "SF"},
],
multi=True,
close_on_select=False,
),
html.Div(id="dropdown-value", style={"height": "10px", "width": "10px"}),
]
)

@app.callback(
Output("dropdown-value", "children"),
[Input("multi-dropdown", "value")],
)
def update_value(val):
return json.dumps([v for v in val])

dash_dcc.start_server(app)
dropdown = dash_dcc.find_element("#multi-dropdown")
dropdown.click()
outer_menu = dash_dcc.find_element("#multi-dropdown .Select-menu-outer")
outer_menu.click()
dash_dcc.wait_for_contains_class("#multi-dropdown .Select", "is-open")
outer_menu.click()
dash_dcc.wait_for_contains_class("#multi-dropdown .Select", "is-open")
dash_dcc.find_element("body").send_keys(Keys.ESCAPE)

dash_dcc.wait_for_text_to_equal("#dropdown-value", '["MTL", "SF"]')


def test_ddcos002_multi_close(dash_dcc):
app = Dash(__name__)
app.layout = html.Div(
[
dcc.Dropdown(
id="multi-dropdown",
options=[
{"label": "New York City", "value": "NYC"},
{"label": "Montreal", "value": "MTL"},
{"label": "San Francisco", "value": "SF"},
],
multi=True,
close_on_select=True,
),
html.Div(id="dropdown-value", style={"height": "10px", "width": "10px"}),
]
)

@app.callback(
Output("dropdown-value", "children"),
[Input("multi-dropdown", "value")],
)
def update_value(val):
return json.dumps([v for v in val])

dash_dcc.start_server(app)
dropdown = dash_dcc.find_element("#multi-dropdown")
dropdown.click()
outer_menu = dash_dcc.find_element("#multi-dropdown .Select-menu-outer")
outer_menu.click()
dash_dcc.wait_for_no_elements("#multi-dropdown .Select-menu-outer")
dash_dcc.find_element("body").send_keys(Keys.ESCAPE)

dash_dcc.wait_for_text_to_equal("#dropdown-value", '["MTL"]')


def test_ddcos003_single_open(dash_dcc):
app = Dash(__name__)
app.layout = html.Div(
[
dcc.Dropdown(
id="multi-dropdown",
options=[
{"label": "New York City", "value": "NYC"},
{"label": "Montreal", "value": "MTL"},
{"label": "San Francisco", "value": "SF"},
],
close_on_select=True,
),
html.Div(id="dropdown-value", style={"height": "10px", "width": "10px"}),
]
)

@app.callback(
Output("dropdown-value", "children"),
[Input("multi-dropdown", "value")],
)
def update_value(val):
return json.dumps(val)

dash_dcc.start_server(app)
dropdown = dash_dcc.find_element("#multi-dropdown")
dropdown.click()
outer_menu = dash_dcc.find_element("#multi-dropdown .Select-menu-outer")
outer_menu.click()
dash_dcc.wait_for_no_elements("#multi-dropdown .Select-menu-outer")
dash_dcc.find_element("body").send_keys(Keys.ESCAPE)

dash_dcc.wait_for_text_to_equal("#dropdown-value", '"MTL"')