Skip to content

Commit bd1a313

Browse files
committed
Fix Dropdown comma in value. #1908
1 parent 23d7014 commit bd1a313

File tree

2 files changed

+10
-23
lines changed

2 files changed

+10
-23
lines changed

Diff for: components/dash-core-components/src/fragments/Dropdown.react.js

+4-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {isNil, pluck, omit, type, without} from 'ramda';
1+
import {isNil, pluck, omit, without} from 'ramda';
22
import React, {useState, useCallback, useEffect, useMemo} from 'react';
33
import ReactDropdown from 'react-virtualized-select';
44
import createFilterOptions from 'react-select-fast-filter-options';
@@ -21,8 +21,6 @@ const TOKENIZER = {
2121
},
2222
};
2323

24-
const DELIMITER = ',';
25-
2624
const Dropdown = props => {
2725
const {
2826
id,
@@ -46,11 +44,6 @@ const Dropdown = props => {
4644
];
4745
}, [options]);
4846

49-
const selectedValue = useMemo(
50-
() => (type(value) === 'Array' ? value.join(DELIMITER) : value),
51-
[value]
52-
);
53-
5447
const onChange = useCallback(
5548
selectedOption => {
5649
if (multi) {
@@ -88,13 +81,13 @@ const Dropdown = props => {
8881
setProps({value: without(invalids, value)});
8982
}
9083
} else {
91-
if (!values.includes(selectedValue)) {
84+
if (!values.includes(value)) {
9285
setProps({value: null});
9386
}
9487
}
9588
setOptionsCheck(sanitizedOptions);
9689
}
97-
}, [sanitizedOptions, optionsCheck, multi, value, selectedValue]);
90+
}, [sanitizedOptions, optionsCheck, multi, value]);
9891

9992
return (
10093
<div
@@ -108,7 +101,7 @@ const Dropdown = props => {
108101
<ReactDropdown
109102
filterOptions={filterOptions}
110103
options={sanitizeOptions(options)}
111-
value={selectedValue}
104+
value={value}
112105
onChange={onChange}
113106
onInputChange={onInputChange}
114107
backspaceRemoves={clearable}

Diff for: components/dash-core-components/tests/integration/dropdown/test_dynamic_options.py

+6-12
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,18 @@ def update_options(search_value):
5252
assert dash_dcc.get_logs() == []
5353

5454

55-
def test_dddo002_array_value(dash_dcc):
56-
dropdown_options = [
57-
{"label": "New York City", "value": "New,York,City"},
58-
{"label": "Montreal", "value": "Montreal"},
59-
{"label": "San Francisco", "value": "San,Francisco"},
60-
]
61-
55+
def test_dddo002_array_comma_value(dash_dcc):
6256
app = Dash(__name__)
63-
arrayValue = ["San", "Francisco"]
6457

6558
dropdown = dcc.Dropdown(
66-
options=dropdown_options,
67-
value=arrayValue,
59+
options=["New York, NY", "Montreal, QC", "San Francisco, CA"],
60+
value=["San Francisco, CA"],
61+
multi=True,
6862
)
69-
app.layout = html.Div([dropdown])
63+
app.layout = html.Div(dropdown)
7064

7165
dash_dcc.start_server(app)
7266

73-
dash_dcc.wait_for_text_to_equal("#react-select-2--value-item", "San Francisco")
67+
dash_dcc.wait_for_text_to_equal("#react-select-2--value-0", "San Francisco, CA\n ")
7468

7569
assert dash_dcc.get_logs() == []

0 commit comments

Comments
 (0)