Constraint Select width for long item #438
-
What is best way to constraint select width? I am using Radix themes, and I see that the trigger has text-overflow ellipsis so I could just set a width to it like .rt-SelectTriggerInner {
max-width: 150px;
} Is there a better way like some prop or css variable to do this? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
a. Use layout components: <Box width="150px">
<Select.Root>...</Select.Root>
</Box> b. Use inline styles <Select.Root>
<Select.Trigger style={{ width: 150 }} />
...
</Select.Root> I wouldn't recommend to target the internal CSS classes because the implementation may change in future versions. See these guides on Layout and Styling for more detail. |
Beta Was this translation helpful? Give feedback.
-
Thanks, solution A looks better to me, however I have to use the Flex since I am inside a Flex and the Box for some reasons doesn't get aligned horizontally even if parent Flex has align center. |
Beta Was this translation helpful? Give feedback.
-
Yeah wrapping with a Flex is common too, you are seeing the default CSS behaviour with inline element alignment |
Beta Was this translation helpful? Give feedback.
-
Sorry but it seems doesn't works using the Box nor Flex, when I first time tested I still had my custom styles. The problem is that Flex nor Box has overflow hidden and even with fixed width the select trigger is being shown. I tried to use overflowX hidden but then select arrow is hidden.
Is there another solution or have to use inline style? For me is not suitable inline style as I need to set max width only on small screen, which I can do with Box but not with inline style. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Nice trick, thanks! This works even with Box. |
Beta Was this translation helpful? Give feedback.
a. Use layout components:
b. Use inline styles
I wouldn't recommend to target the internal CSS classes because the implementation may change in future versions. See these guides on Layout and Styling for more detail.