picker
picker copied to clipboard
how to make placeholder
How to make placeholder or how to make the picker doesnt auto select from our state ?
This is'nt the best solution, but it was the only one I found.
Place a first children as <Picker.Item value='' label='Placeholder text...' />
https://stackoverflow.com/questions/37440464/have-a-placeholder-for-react-native-picker
Used similar but added also enabled={false} so user can't select the placeholder.
<ReactNativePicker.Item label={placeholder} enabled={false} />
Used similar but added also enabled={false} so user can't select the placeholder.
<ReactNativePicker.Item label={placeholder} enabled={false} />
Doing this forces you to have to press the dropdown icon to open the picker instead of being able to press the input as normal, which obviously isn't great but it's our only option currently 😒
To counter act this, I added the following:
const [pickerFocused, setPickerFocused] = useState(false)
<Picker
// other props
onFocus={() => setPickerFocused(true)}
onBlur={() => setPickerFocused(false)}
>
<Picker.Item
value=""
label="My custom placeholder"
enabled={!pickerFocused}
/>
</>
Used similar but added also enabled={false} so user can't select the placeholder.
<ReactNativePicker.Item label={placeholder} enabled={false} />
It works on me, Thanks a lot
I was using react native picker , I was getting list from backend and i have to show it and then select it . I achieved it using . <Picker.Item value='' label='Choose State' enabled={false} />
{STATES_LOOKUP && STATES_LOOKUP.map((item, index) => (
<Picker.Item
itemStyle={{
color: COLORS.RED.Orange
}} label={item.label} value={item.value} />
))
}