picker
picker copied to clipboard
Cannot open or close picker by focus and blur methods.
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
I got the same issue.
RN: 0.63.2
"@react-native-picker/picker": "1.9.2"
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.
Time being I user https://github.com/beefe/react-native-picker this one. can you please tell from where this useRef
coming from?
@bhardwajMehul
import {useRef} from "react"