picker icon indicating copy to clipboard operation
picker copied to clipboard

Cannot open or close picker by focus and blur methods.

Open bhardwajMehul opened this issue 3 years ago • 4 comments

const pickerRef = useRef();

function open() {
  pickerRef.current.focus();
}

function close() {
  pickerRef.current.blur();
}

return <Picker
  ref={pickerRef}
  selectedValue={selectedLanguage}
  onValueChange={(itemValue, itemIndex) =>
    setSelectedLanguage(itemValue)
  }>
  <Picker.Item label="Java" value="java" />
  <Picker.Item label="JavaScript" value="js" />
</Picker>

I'm unable to open or close picker by the focus and blur methods. The current attribute does not contains the methods.

Instead these methods should be available in the Picker class only. like https://github.com/beefe/react-native-picker

bhardwajMehul avatar Jul 01 '21 11:07 bhardwajMehul

I got the same issue. RN: 0.63.2 "@react-native-picker/picker": "1.9.2"

MathieuRA avatar Jul 23 '21 18:07 MathieuRA

That's my versions: RN 0.64.2 "@react-native-picker/picker": "^1.16.4"

My component does work. That's my snippet:

const App = () => {
  const pickerRef = useRef();
  
  function openPicker() {
    pickerRef.current.focus();
  }
  
  function closePicker() {
    pickerRef.current.blur();
  }

  return (
    <>
      <Button title="Press me" onPress={openPicker}
      <Picker
        ref={pickerRef}
        selectedValue={selectedLanguage}
        onValueChange={(itemValue, itemIndex) =>
          setSelectedLanguage(itemValue)
        }>
        <Picker.Item label="Java" value="java" />
        <Picker.Item label="JavaScript" value="js" />
      </Picker>
    </>
  )
}

In your snippet the call to open() function is missing, so if you want to share the full snippet I'm happy to help.

andrespaggy avatar Aug 10 '21 11:08 andrespaggy

Time being I user https://github.com/beefe/react-native-picker this one. can you please tell from where this useRef coming from?

bhardwajMehul avatar Aug 10 '21 13:08 bhardwajMehul

@bhardwajMehul import {useRef} from "react"

bitshop avatar Dec 07 '21 05:12 bitshop