react-select icon indicating copy to clipboard operation
react-select copied to clipboard

Support inline-block / sizes

Open dantman opened this issue 11 years ago • 40 comments

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.

dantman avatar Jul 19 '15 07:07 dantman

+1

danilotorrisi avatar Aug 12 '15 16:08 danilotorrisi

@dantman can't you just put the Select inside an inline-block?

mik01aj avatar Aug 24 '15 15:08 mik01aj

@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.

dantman avatar Aug 25 '15 05:08 dantman

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)?

alesn avatar Sep 30 '15 15:09 alesn

ping @jossmac

JedWatson avatar Sep 30 '15 16:09 JedWatson

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?

jossmac avatar Sep 30 '15 23:09 jossmac

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

alesn avatar Oct 01 '15 08:10 alesn

+1

bcardiff avatar Oct 21 '15 19:10 bcardiff

+1

freder avatar Oct 22 '15 08:10 freder

+1

tonybaroneee avatar Nov 05 '15 22:11 tonybaroneee

+1

gsdean avatar Dec 02 '15 21:12 gsdean

Update: the reason we haven't gone ahead with this feature is two fold;

  1. 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
  2. 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?

jossmac avatar Dec 03 '15 05:12 jossmac

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 avatar Dec 03 '15 15:12 tonybaroneee

@tonybaroneee sounds good man, would you mind submitting a PR?

jossmac avatar Dec 03 '15 22:12 jossmac

Sure, I'll try to get to it soon.

tonybaroneee avatar Dec 03 '15 23:12 tonybaroneee

that would be pretty useful, can't wait to see the PR :+1:

Nyalab avatar Dec 16 '15 14:12 Nyalab

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 :)

cedricdelpoux avatar Dec 16 '15 14:12 cedricdelpoux

+1

brutcha avatar Dec 23 '15 09:12 brutcha

@tonybaroneee any word on that PR?

jossmac avatar Dec 24 '15 01:12 jossmac

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 .

tonybaroneee avatar Dec 24 '15 13:12 tonybaroneee