Multi Select: display only selected items count after x number of items are selected/shown in chips
See original GitHub issueThank you for all of the work you do on RS 😃
I am looking to customize the multiselect and wondering if you have a recommendation for how to achieve the desired results.
Right now, with many selections the select component takes up a prohibitive amount of space for certain UIs. I’d like to utilize the chip display within the input but show only a few selected options (like 3/4 max) and then add a “badge” count for the number of selected options that aren’t shown in the value container in the input. The options that are selected but are past the max number of chips allowed to show in the input should show as selected within the dropdown list. I’ve implemented part of this with using a custom ValueContainer
to show only the first few chip selections, and then add a count of additional selections. I’m unsure of how I can utilize prop hideSelectedOptions
to achieve this to show selected items in the list only when my max is met…
Here’s what I have so far: https://codesandbox.io/s/custom-react-select-sjtib
Current:
Desired:
Issue Analytics
- State:
- Created 4 years ago
- Comments:11
Top GitHub Comments
I was trying to do the same in an
AsyncSelect
and I managed to create a solution based on @ebonow 's solution.So, I’m sharing a partial example of what I did to make it work, because this might help others:
The trick here is to understand that the first child of the
ValueContainer
is the array of selected options when the input has values. With this in mind, I could just make a slice (in my case showing the last two selected options) and return the chips, the counter and the remaning children after it.But, do notice this: when the
hasValue
returnsfalse
you can’t do a slice because the first child is not the array of selected options. Hence the guard-clause.Hope this helps.
I noticed that there was a bug so I made an update to the above sandbox to instead use the MultiValue instead of the ValueContainer.
https://codesandbox.io/s/custom-visible-multivalues-8zh8c?file=/example.js