Replies: 2 comments
-
Unfortunately there's no straightforward answer I can give you for this. You can do some basic style changes like setting a max height on the <Select
chakraStyles={{
control: (provided) => ({
...provided,
maxH: "40px",
}),
}}
/> Something else you could do would be to set The only way to do the last thing you said where you show "and N other options" would be to make a custom component for it, and I don't really have a simple solution for that to give you. |
Beta Was this translation helpful? Give feedback.
-
I recently found somewhat of a solution to this problem, that I posted on a related posts, but I'll copy it here for visibility. My solution was to show a user defined quantity N tags and then show a fake tag with the label "N More Tags" after it to prevent the contents of the field from getting too long. I also have a note at the bottom about how this solution is not bulletproof to prevent line wrapping, but it's a start. Hey, I know this question was from a while ago but I recently had to implement something like this for my company's production application, so after some trial and error I found what I believe to be a good solution. And hopefully if anyone else comes across this thread it can help them as well. My trick was to use react's const MAX_DISPLAY_TAGS = 3;
const ValueContainer = ({
children,
...props
}: ValueContainerProps<StateOption, true>) => {
const selectedCount = props.getValue().length;
const overflowCount = selectedCount - MAX_DISPLAY_TAGS;
return (
<chakraComponents.ValueContainer {...props}>
{Children.map(children, (child, childIndex) => {
// We need to include the InputContainer, which is the last child
// so only replace children after index 4 and before the last child
if (childIndex !== selectedCount) {
if (childIndex === MAX_DISPLAY_TAGS) {
return <Tag m={0.5}>{overflowCount} More States</Tag>;
}
if (childIndex > MAX_DISPLAY_TAGS) {
return null;
}
}
return child;
})}
</chakraComponents.ValueContainer>
);
}; This produces something that looks like this: ![]() And here's a full CodeSandbox example: https://codesandbox.io/s/vpnzhd?file=/app.tsx Something to note for this solution, if the goal is to never have the tags wrap to the next line, this won't really guarantee that. To be sure it will never wrap, you'd have to make sure that the longest X (however many your max is) tag labels selected will never be longer than their container. This is difficult to guarantee on a mobile layout especially, unless your limit is to only display one real tag followed by a tag count. |
Beta Was this translation helpful? Give feedback.
-
When you check more than some options from the dropdown the input make its height higher and higher which does not looks nice in the end. Is it somehow possible to make with maximum of height, lets say, 30px and if there are more options select instead of all values displayed, the number of how many options were selected or at least display some dots that can indicate that there are more options selected?
Below I paste how it looks like currently. The multi select it's not alligned any more with the rest of the inputs.

Beta Was this translation helpful? Give feedback.
All reactions