picker icon indicating copy to clipboard operation
picker copied to clipboard

how to make placeholder

Open androxxe opened this issue 5 years ago • 5 comments

How to make placeholder or how to make the picker doesnt auto select from our state ?

androxxe avatar Jun 03 '20 19:06 androxxe

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

nando-carvalho avatar Jun 10 '20 12:06 nando-carvalho

Used similar but added also enabled={false} so user can't select the placeholder.

<ReactNativePicker.Item label={placeholder} enabled={false} />

hixus avatar Jul 01 '21 08:07 hixus

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}
  />
</>

chrise86 avatar Oct 06 '21 08:10 chrise86

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

majecthoughts0517 avatar Dec 04 '21 12:12 majecthoughts0517

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} />
                                    ))
                                    }

FaisalKhawaj avatar Mar 03 '22 11:03 FaisalKhawaj