React-autosuggest: focus autosuggest input programmatically using ref?

Created on 29 Mar 2019  路  3Comments  路  Source: moroshko/react-autosuggest

I have this Wrapper component

<Autosuggest
  getInputValue={this.getInputValue}
  placeholder={placeholder}
  inputRef={this.props.inputRef}
/>

and I have parent a component that does createRef() and pass in inputRef as props to above Wrapper, I thought I can do this.inputRef.current.focus() in the parent component but I seems can't target the input ref of Autosuggest this way.

Any clue?

Most helpful comment

meanwhile, I'm passing a flag from props then pass it to inputProps, it worked.

<Autosuggest
  inputProps={autoFocus: this.props.autoFocusInput}
/>

All 3 comments

meanwhile, I'm passing a flag from props then pass it to inputProps, it worked.

<Autosuggest
  inputProps={autoFocus: this.props.autoFocusInput}
/>

is there no way to pass a ref using useRef() to the input component returned by renderInputComponent via inputProps ?

Now you can pass ref in inputProps. Update to v10.0.1

Was this page helpful?
0 / 5 - 0 ratings