Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set value manually #79

Closed
shilangyu opened this issue Mar 9, 2019 · 8 comments
Closed

Set value manually #79

shilangyu opened this issue Mar 9, 2019 · 8 comments

Comments

@shilangyu
Copy link
Contributor

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

@shilangyu
Copy link
Contributor Author

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
Copy link
Contributor Author

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

@shilangyu shilangyu reopened this Mar 9, 2019
@cvanem
Copy link
Collaborator

cvanem commented Mar 9, 2019

@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
Copy link
Contributor Author

@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
Copy link
Collaborator

cvanem commented Mar 9, 2019

@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
Copy link
Collaborator

cvanem commented Mar 9, 2019

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

@techniq
Copy link
Owner

techniq commented Mar 9, 2019 via email

@shilangyu
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants