Skip to content

Commit

Permalink
Fix Dropdown comma in value. #1908
Browse files Browse the repository at this point in the history
  • Loading branch information
T4rk1n committed Apr 18, 2022
1 parent 6033397 commit a5eef68
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
15 changes: 4 additions & 11 deletions components/dash-core-components/src/fragments/Dropdown.react.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {isNil, pluck, omit, type, without} from 'ramda';
import {isNil, pluck, omit, without} from 'ramda';
import React, {useState, useCallback, useEffect, useMemo} from 'react';
import ReactDropdown from 'react-virtualized-select';
import createFilterOptions from 'react-select-fast-filter-options';
Expand All @@ -21,8 +21,6 @@ const TOKENIZER = {
},
};

const DELIMITER = ',';

const Dropdown = props => {
const {
id,
Expand All @@ -46,11 +44,6 @@ const Dropdown = props => {
];
}, [options]);

const selectedValue = useMemo(
() => (type(value) === 'Array' ? value.join(DELIMITER) : value),
[value]
);

const onChange = useCallback(
selectedOption => {
if (multi) {
Expand Down Expand Up @@ -88,13 +81,13 @@ const Dropdown = props => {
setProps({value: without(invalids, value)});
}
} else {
if (!values.includes(selectedValue)) {
if (!values.includes(value)) {
setProps({value: null});
}
}
setOptionsCheck(sanitizedOptions);
}
}, [sanitizedOptions, optionsCheck, multi, value, selectedValue]);
}, [sanitizedOptions, optionsCheck, multi, value]);

return (
<div
Expand All @@ -108,7 +101,7 @@ const Dropdown = props => {
<ReactDropdown
filterOptions={filterOptions}
options={sanitizeOptions(options)}
value={selectedValue}
value={value}
onChange={onChange}
onInputChange={onInputChange}
backspaceRemoves={clearable}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,18 @@ def update_options(search_value):
assert dash_dcc.get_logs() == []


def test_dddo002_array_value(dash_dcc):
dropdown_options = [
{"label": "New York City", "value": "New,York,City"},
{"label": "Montreal", "value": "Montreal"},
{"label": "San Francisco", "value": "San,Francisco"},
]

def test_dddo002_array_comma_value(dash_dcc):
app = Dash(__name__)
arrayValue = ["San", "Francisco"]

dropdown = dcc.Dropdown(
options=dropdown_options,
value=arrayValue,
options=["New York, NY", "Montreal, QC", "San Francisco, CA"],
value=["San Francisco, CA"],
multi=True,
)
app.layout = html.Div([dropdown])
app.layout = html.Div(dropdown)

dash_dcc.start_server(app)

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

assert dash_dcc.get_logs() == []

0 comments on commit a5eef68

Please sign in to comment.