question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Styling Select.Value

See original GitHub issue

https://github.com/radix-ui/primitives/blob/23b934c1aeed966f15fda1222655f24fb0b5f311/packages/react/select/src/Select.tsx#L251

I’m not sure how important it is for Select.Value to not be styled. It’s preventing me from using Select.Trigger as a flex container and adding flex: 1 to Select.Value to get the select to stretch to fill the container.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
iammolacommented, Jun 28, 2022

HI @benoitgrelard.

The first method is the better option for me. I had no idea you were allowed to do that though and I can see how both methods can be overused to avoid the style filtering on the Select.Value.

Now I’ve seen it’s possible/allowed to add a parent to the Select.Value. From what I can assume, any extra styles you want on it can be done that way. Like in @avin-kavish’s case, If I add flex: 1, the extra span does fill the container, and the Select.Value does as well.

Screenshot 2022-06-28 at 14 00 07

So just using another parent may work for simple cases and you probably won’t have to change anything with the current behaviour, but add a section in the docs talking about adding an extra parent as a means to add styles to the Select.Value that the user is sure won’t change its original position. I’m obviously not sure and haven’t run any tests, so If what I’m saying isn’t stable or advised or straight-up crap, forgive me🙏.

Thanks again and have a nice rest of your day. I appreciate it 🙌

1reaction
benoitgrelardcommented, Jun 28, 2022

Hey @iammola,

Yeah the truncating/ellipsis is definitely one I’ve been thinking about. I am reluctant to add “easy” styling of Value though but perhaps as people will expect it to “just work” in all cases. But maybe I am worrying too much… not sure.

In the meantime, you could do this as an escape hatch:

<Select.Trigger style={styles.trigger}>
+  <span style={{ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
    <Select.Value />
+  </span>
  <Select.Icon />
</Select.Trigger>

Or, you could even use CSS to target that first span:

.trigger > span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

I am aware that with that second method you can still break it by adding padding-left for example, because you’re now adding styles directly to the value, rather than a parent, but at least you have to get out of your way to break it.

What do you think?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to style the option of an html "select" element?
This is a html css code used to style option and select tag. Selected option : background and bold After closing , it...
Read more >
How To Create Custom Select Menus - W3Schools
Surround the select box within a "custom-select" DIV element. Remember to set the width: --> <div class="custom-select" style="width:200px;"> <select>
Read more >
Custom Select Styles with Pure CSS | Modern CSS Solutions
Modern CSS gives us a range of properties to achieve custom select styles that have a near-identical initial appearance.
Read more >
Styling the Standard Select with CSS and HTML
Learn how to style custom with CSS and HTML. Web developers follow along with code examples in this programming tutorial.
Read more >
HTML select style Attribute - Dofactory
A style attribute on a <select> tag assigns a unique style to the dropdown. Its value is CSS that defines the appearance of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found