Support inline-block / sizes
react-select only seems to work as a full-width block component. It would be nice if it would also support use as an inline-block component (like a standard <select>) with either an auto-calculated width or a specified width.
+1
@dantman can't you just put the Select inside an inline-block?
@dantman can't you just put the Select inside an inline-block?
That is what I'm doing now. But A) it should not be necessary and B) automatic sizing (like how normal selects work) cannot be done that way.
Is there a way to make react-select be auto-sized (by content size) and not take up the full width of its parent (or having to be sized to a fixed width that would have to be calculated somehow from the content)?
ping @jossmac
I was going to say wrap it, but that's been covered by @mik01aj
@dantman because I haven't needed this personally I'm having trouble imagining how it would be used. Could you please provide a use case, preferably with screenshots?
I've created a jsfiddle demonstrating different use cases https://jsfiddle.net/Lp51Ldu8/1/ I included notes directly in the fiddle. Defining a fixed width would be ok e.g. for measurements units but for localized names of levels (different length in different languages), it would not be the best solution.
In simple terms, I would need a react select component that can behave the same as the standard html select input control in terms of being an inline element sized by its content width. Even just react-select component having the width - both when open and closed - as the longest option, would be sufficient for me
+1
+1
+1
+1
Update: the reason we haven't gone ahead with this feature is two fold;
- To get the desired width of the component we would have to loop through each of the children finding the option with the greatest character length, which would decrease performance
- After arriving at this number we'll have to add some fuzzy logic by getting the current font-size and multiplying from there to arrive at the width. This could go horribly wrong in a few cases
If using a fixed-width works for your application, I recommend wrapping the react-select component with your own and handling the inline-block and max-width declarations inside of it. Something like this:
displayName: 'MySelect',
render () {
return (
<div style={{ display: 'inline-block', maxWidth: this.props.maxWidth }}>
<ReactSelect {...this.props} />
</div>
)
}
<MySelect ... />
ping @JedWatson safe to close?
Hey @jossmac, it's actually way less complicated than that. It basically involves changing .Select-control to width: auto and having the .Select-value not be absolutely-positioned (plus a few other css cleanups).
@tonybaroneee sounds good man, would you mind submitting a PR?
Sure, I'll try to get to it soon.
that would be pretty useful, can't wait to see the PR :+1:
Hey, I really need this feature. I tried to change what you said @tonybaroneee but it was not as simple as you said because we need to handle the search feature and the multi feature. So I hope you found the solution :)
+1
@tonybaroneee any word on that PR?
Sorry for the delay, been super busy. I'm home on break now, so will try to work on it this week! On Dec 23, 2015 8:56 PM, "Joss Mackison" [email protected] wrote:
@tonybaroneee https://github.com/tonybaroneee any word on that PR?
— Reply to this email directly or view it on GitHub https://github.com/JedWatson/react-select/issues/323#issuecomment-167022696 .