React-native-picker-select: Programmatically focus picker

Created on 25 Sep 2018  Â·  9Comments  Â·  Source: lawnstarter/react-native-picker-select

Is your feature request related to a problem? Please describe.
I have a form with several fields, a couple text inputs followed by a picker. I'd like to use the 'Next' button on the iOS/Android keyboard to programmatically focus the picker.

Describe the solution you'd like
A method that programmatically focuses the picker.

Most helpful comment

Just to confirm, yes this.refs['picker'].togglePicker() worked.

Calling togglePicker outside of the component does not seem to work for me:

this.select.current.togglePicker();

<RNPickerSelect
    ref={this.select}
    onValueChange={fn}
    items={[]}
/>

This seems to work on iOS but not android.

All 9 comments

It's apparently undocumented, but have you tried togglePicker()?

@sidraval does togglePicker solve your needs on iOS?

For Android, this issue exists on the feature req board as #22

@sidraval let me know if that solves it so i can close this out

@lfkwtz My project wrapped up, so I can't test togglePicker() anymore – I'll close this out now

Just to confirm, yes this.refs['picker'].togglePicker() worked.

Just to confirm, yes this.refs['picker'].togglePicker() worked.

Calling togglePicker outside of the component does not seem to work for me:

this.select.current.togglePicker();

<RNPickerSelect
    ref={this.select}
    onValueChange={fn}
    items={[]}
/>

Just to confirm, yes this.refs['picker'].togglePicker() worked.

Calling togglePicker outside of the component does not seem to work for me:

this.select.current.togglePicker();

<RNPickerSelect
    ref={this.select}
    onValueChange={fn}
    items={[]}
/>

This seems to work on iOS but not android.

see link above ^ #22

Outside of the component calling open works for me

class InputSelect {
  private picker;
  render() {
    return (
      <RNPickerSelect ref={e => this.picker = e} ... />
    )
  }
  open() { this.picker.togglePicker() }
}

Was this page helpful?
0 / 5 - 0 ratings