Skip to content

Commit

Permalink
Handle multiple dropdown search cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
T4rk1n committed Jul 4, 2022
1 parent 0f1555d commit abbe769
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 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, without, pick, head} from 'ramda';
import {isNil, pluck, without, pick} 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 Down Expand Up @@ -47,26 +47,23 @@ const Dropdown = props => {
} = props;
const [optionsCheck, setOptionsCheck] = useState(null);
const [sanitizedOptions, filterOptions] = useMemo(() => {
let sanitized = sanitizeOptions(options);
const firstOption = sanitized ? head(sanitized) : null;
let labelKey = 'label';
if (firstOption && firstOption.search) {
labelKey = 'search';
} else if (firstOption && React.isValidElement(firstOption.label)) {
// Auto put the value as search
labelKey = 'search';
sanitized = sanitized.map(option => ({
const sanitized = sanitizeOptions(options).map(option => {
let search = option.search || option.label;
if (React.isValidElement(search)) {
search = String(option.value);
}
return {
...option,
search: `${option.value}`,
}));
}
search,
};
});

return [
sanitized,
createFilterOptions({
options: sanitized,
tokenizer: TOKENIZER,
labelKey,
labelKey: 'search',
}),
];
}, [options]);
Expand Down

0 comments on commit abbe769

Please sign in to comment.