最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - React-Select: keep selected items in menu - Stack Overflow

programmeradmin2浏览0评论

Using React-Select in v1.0.0-beta10, I'd like to keep selected items in menu in order to be able to implement a dropdown behaving similar as the multi-select at MaterializeCss

here's a screenshot:

how to achieve this behavior?

Using React-Select in v1.0.0-beta10, I'd like to keep selected items in menu in order to be able to implement a dropdown behaving similar as the multi-select at MaterializeCss

here's a screenshot:

how to achieve this behavior?

Share Improve this question edited Feb 29, 2016 at 13:53 FranBran asked Feb 29, 2016 at 13:47 FranBranFranBran 1,0272 gold badges11 silver badges32 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 17

Just to have this plete as you asked in react-select on GitHub this was made possible using removeSelected={false} in this pull request. Now (mid 2019) the solution is:

hideSelectedOptions={false}

You have access to a prop called filterOptions that accepts a function that takes the properties options, searchFilter and selectedOptions.

You should just be able to always return options that match the search filter instead of stripping out the selectedOptions something like below (if you are using underscrore/lodash. Or write your own method.

const filterOptions = (options, searchFilter, selectedOptions) => {
  return _.filter(options, options => _.includes(option.value, searchFilter));
}

and then

<Select {...props} filterOptions={filterOptions} />

Hope this example helps.

发布评论

评论列表(0)

  1. 暂无评论