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 Related StackOverflow Question
I was trying to do the same in an
AsyncSelectand 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
ValueContaineris 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
hasValuereturnsfalseyou 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