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

Commit e7feb84

Browse files
author
Shammamah Hossain
committed
Fix clearable bug for single-option dropdowns.
1 parent 718ae50 commit e7feb84

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

src/fragments/Dropdown.react.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ export default class Dropdown extends Component {
7575
onChange={selectedOption => {
7676
if (multi) {
7777
let value;
78-
if (isNil(selectedOption)) {
78+
if (isNil(selectedOption) && this.props.clearable) {
7979
value = [];
8080
} else {
8181
value = pluck('value', selectedOption);
8282
}
8383
setProps({value});
8484
} else {
8585
let value;
86-
if (isNil(selectedOption)) {
86+
if (isNil(selectedOption) && this.props.clearable) {
8787
value = null;
8888
} else {
8989
value = selectedOption.value;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import dash
2+
from dash.dependencies import Input, Output
3+
import dash_core_components as dcc
4+
import dash_html_components as html
5+
6+
from selenium.webdriver.common.keys import Keys
7+
8+
9+
def test_ddcf001_clearable_false_single(dash_duo):
10+
app = dash.Dash(__name__)
11+
app.layout = html.Div([
12+
dcc.Dropdown(
13+
id='my-unclearable-dropdown',
14+
options=[
15+
{'label': 'New York City', 'value': 'NYC'},
16+
{'label': 'Montreal', 'value': 'MTL'},
17+
{'label': 'San Francisco', 'value': 'SF'},
18+
],
19+
value='MTL',
20+
clearable=False
21+
),
22+
html.Div(
23+
id='dropdown-value',
24+
style={'height': '10px', 'width': '10px'}
25+
)
26+
])
27+
28+
@app.callback(
29+
Output('dropdown-value', 'children'),
30+
[Input('my-unclearable-dropdown', 'value')]
31+
)
32+
def update_value(val):
33+
return val
34+
35+
dash_duo.start_server(app)
36+
37+
dropdown = dash_duo.find_element('#my-unclearable-dropdown input')
38+
dropdown.send_keys(Keys.BACKSPACE)
39+
dash_duo.find_element('#dropdown-value').click()
40+
41+
assert len(dash_duo.find_element('#dropdown-value').text) > 0

0 commit comments

Comments
 (0)