In my react-select drop-down, the labels are hundreds of characters long. In the Control chips, I would like to show a shorter version of what's in the drop-down. Is this possible?
Edit: I want to set the text of the chip, not pixel width.
In my react-select drop-down, the labels are hundreds of characters long. In the Control chips, I would like to show a shorter version of what's in the drop-down. Is this possible?
Edit: I want to set the text of the chip, not pixel width.
SOLUTION 1
You can custom the style of the control chips when using the multiple value
Select
with the propsstyles
like the following example:Here a live example of shorter versions of long label. I put special (and ugly) background so you can see where each container starts and ends.
SOLUTION 2
Following the comment request this is an alternative solution to cut the selected option. You can overwrite the component
MultiValue
with the propcomponents
. Inside this component you will have access to the option label and applysubstring
function to truncate the label as short as you can.Here a live example of this alternative option.
SOLUTION 3
In the same idea as the solution 2 if you know in advance your option labels and the crop you want to display you can set an extra props in your
options
array like this:And then overwrite the component with the following code:
Here a live example.
SOLUTION FOR SINGLE VALUE
If you want to display a different value than in options for
SingleValue
select I recommend to use the solution 3 and change the component like this:Here a live example.