techniq / mui-downshift

Thin layer over paypal's downshift to use Material UI visual components
https://techniq.github.io/mui-downshift/
MIT License
92 stars 24 forks source link

Set value manually #79

Closed shilangyu closed 5 years ago

shilangyu commented 5 years ago

How do I set the current value programmatically? I want to create a default value during render.

shilangyu commented 5 years ago

Should've done much more research before posting, stories' code helped a lot:

<MuiDownshift
  getInputProps={() => ({
     value: 'default value'
  })}
  items={filteredItems}
  inputRef={node => {
    this.input = node
  }}
/>
shilangyu commented 5 years ago

The above method works only visually, mui-downshift doesnt see the value. Reopening.

cvanem commented 5 years ago

@shilangyu As this is a wrapper over downshift, I think you need to pass in the actual downshift props to set the initial value or selected value.

See initialSelectedItem and initialInputValue

shilangyu commented 5 years ago

@cvanem thank you for your reply. I tried both and couldnt get them to work:

<MuiDownshift
  initialInputValue={'default value'}
  items={filteredItems}
  inputRef={node => {
    this.input = node
  }}
/>
<MuiDownshift
  initialSelectedItem={'default value'}
  items={filteredItems}
  inputRef={node => {
    this.input = node
  }}
/>
cvanem commented 5 years ago

@shilangyu It doesn't appear to be working for me either.
It looks like this package may be using an older version of downshift. See old documentation.

I was able to get it working with defaultSelectedItem:

<StarWarsSelect defaultSelectedItem={{ label: '4-LOM', value: 0 }} />
cvanem commented 5 years ago

@techniq Is it time to update this library to downshift 3.x? It looks like it is still using 2.x.

techniq commented 5 years ago

Sure. I'd really like to finish the rewrite to drop react-virtualize so it's all part of the next major semver.

On Sat, Mar 9, 2019, 4:28 PM cvanem notifications@github.com wrote:

@techniq https://github.com/techniq Is it time to update this library to downshift 3.x? It looks like it is still using 2.x.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/techniq/mui-downshift/issues/79#issuecomment-471223588, or mute the thread https://github.com/notifications/unsubscribe-auth/AAK1RGGKF100PpNr0JsCY3nO_ZkJHZ5Bks5vVCeJgaJpZM4bm0Jt .

shilangyu commented 5 years ago

Downshift 2.x method did work for mui-downshift v1.4.1 Thank you for your help