Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit 4c9cbb4

Browse files
author
Shammamah Hossain
committed
Fix clearable bug for multi-option dropdowns.
1 parent e7feb84 commit 4c9cbb4

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/fragments/Dropdown.react.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ export default class Dropdown extends Component {
7474
value={selectedValue}
7575
onChange={selectedOption => {
7676
if (multi) {
77+
if (
78+
!this.props.clearable &&
79+
selectedOption.length < 1
80+
) {
81+
return;
82+
}
7783
let value;
7884
if (isNil(selectedOption) && this.props.clearable) {
7985
value = [];

tests/integration/dropdown/test_clearable_false.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,40 @@ def update_value(val):
3939
dash_duo.find_element('#dropdown-value').click()
4040

4141
assert len(dash_duo.find_element('#dropdown-value').text) > 0
42+
43+
44+
def test_ddcf002_clearable_false_multi(dash_duo):
45+
app = dash.Dash(__name__)
46+
app.layout = html.Div([
47+
dcc.Dropdown(
48+
id='my-unclearable-dropdown',
49+
options=[
50+
{'label': 'New York City', 'value': 'NYC'},
51+
{'label': 'Montreal', 'value': 'MTL'},
52+
{'label': 'San Francisco', 'value': 'SF'},
53+
],
54+
value=['MTL', 'SF'],
55+
multi=True,
56+
clearable=False
57+
),
58+
html.Div(
59+
id='dropdown-value',
60+
style={'height': '10px', 'width': '10px'}
61+
)
62+
])
63+
64+
@app.callback(
65+
Output('dropdown-value', 'children'),
66+
[Input('my-unclearable-dropdown', 'value')]
67+
)
68+
def update_value(val):
69+
return ', '.join(val)
70+
71+
dash_duo.start_server(app)
72+
73+
dropdown = dash_duo.find_element('#my-unclearable-dropdown input')
74+
dropdown.send_keys(Keys.BACKSPACE)
75+
dropdown.send_keys(Keys.BACKSPACE)
76+
dash_duo.find_element('#dropdown-value').click()
77+
78+
assert len(dash_duo.find_element('#dropdown-value').text) > 0

0 commit comments

Comments
 (0)