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.

Fit contents in flex layout

See original GitHub issue

I have a very simple setup - a display: flex header with a logo on the left and a react-select on the right.

image

But, as you can see, react-select doesn’t stretch to fit the value. I’ve tried a lot of options, but nothing seems to work. Does anyone have a solution?

Here’s the sandbox.

I have asked this question on SO as well, with little traction…

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
artoorascommented, Jun 22, 2020

Thanks @ebonow , I ended up using a version of your solution. I used position: relative on singleValue.

1reaction
ebonowcommented, Jun 20, 2020

@artooras Hello again,

The styling I think you are looking for is based on the SingleValue. Since the default styling is set to position: absolute, it will not flex without some styling overrides.

I responded to a thread recently discussing how to create an inline React-Select (with a working sandbox example). While you would likely want to keep the Indicators and borders, it should fit as a proof of concept of flexing the width of the Select to fit the value.

This is likely the bit of styling you are looking for to apply to the SingleValue component

/* Position value relative (instead of absolute) and remove transform and max-width */
.react-select .react-select__single-value {
  position: relative;
  transform: none;
  max-width: none;
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Shrink to fit content in flexbox, or flex-basis - Stack Overflow
I want columns One and Two to shrink/grow to fit rather than being fixed. ... it looks like the column isn't growing to...
Read more >
flex-basis - CSS: Cascading Style Sheets - MDN Web Docs
The flex-basis CSS property sets the initial main size of a flex item. It sets the size of the content box unless otherwise...
Read more >
Shrink flex item to fit content - HTML & CSS - SitePoint Forums
The <a> element stretches as long as the page width. How can we shrink it so it fits the content? ... Use the...
Read more >
How to Make Flex Items Take the Content Width - W3docs
In this snippet, learn how to make flex items take the content width instead of the width of the parent container. Use either...
Read more >
Making width and flexible items play nice together | CSS-Tricks
The short answer: flex-shrink and flex-basis are probably what you're ... Let's say you want to align an image and some text next...
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