downshift icon indicating copy to clipboard operation
downshift copied to clipboard

manually update downshift's internal state of input field

Open scottjason opened this issue 9 years ago • 2 comments

  • downshift 1.4.0:
  • node version: 7.4.0
  • yarn: 0.19.1

Relevant code or config

  onStateChange(selected, dsProps) {
    this.props.setInputAndSelectedType(dsProps.getInputProps().value, selected.type)
  },

Problem description:

Hi again. I'm using downshift for Instacart's main new search component and need to be able to replicate what we're currently doing, which is:

When a user highlights a suggested item (presses down), replace the input field with whatever is highlighted. This behavior can also be seen on google's search bar.

Right now, under downshifts actions, I don't see any exposed functions I can call to update downshifts internal state of the input field. Also, all the examples show that the input field is not being updated to correspond with the highlighted item.

So in the relevant code above, is there a way I can update downshift's internal state of the input field before setting this value in redux?

I understand that inputValue is a Control Prop and that my "child callback function" should be able to update this, but am still a bit unclear on how to do so.

Thanks for any help! :)

Suggested solution:

Expose function to update downshift's internal state of the input field.

scottjason avatar Sep 11 '17 20:09 scottjason

Thanks for asking :)

Check out this example. Here's the code

If you'd like to clean up that example a bit and put it in a codesandbox then we could include it in the list on the README so folks will find it easier :)

Let me know if this doesn't solve your problem :)

kentcdodds avatar Sep 11 '17 20:09 kentcdodds

Great, thank you. Yes, I'll definitely try to clean up this example and put in a codebox. Thanks for being so quick to respond, @kentcdodds! 👍

scottjason avatar Sep 11 '17 21:09 scottjason