React-native-picker-select: Picker on iOS selects an item and closes the drawer before Done button is clicked

Created on 6 Nov 2020  路  9Comments  路  Source: lawnstarter/react-native-picker-select


Describe the bug

Picker on iOS selects an item in the list and closes the drawer before button Done is clicked.

To Reproduce

You can see it in this simple example:
https://snack.expo.io/@betabit/react-native-picker-select

Select picker, scroll to choose second item. Drawer will be closed before Done button is clicked.

Expected behavior

Selection of the item should be after button Done is clicked, and only then should the drawer close.

Screenshots

n/a
Additional details

Reproduction and/or code sample

https://snack.expo.io/@betabit/react-native-picker-select


Most helpful comment

@milennaj
same problem !
i could fix it by remove key prop on RNPickerSelect component

All 9 comments

@milennaj
same problem !
i could fix it by remove key prop on RNPickerSelect component

Removing the key is not a solution since then we will get a warning: Cannot update component inside function and issue:
https://github.com/lawnstarter/react-native-picker-select/issues/346

@milennaj
I got this warning when I tried to set a value that is not available in the items list

@ArianHamdi yes, that was the problem. Initially in the code we were setting the value to the object that isn't in the list. Thank you.

Hi I have the same issue, and removing the key prop doesn't solve it in my case since from the begining it wasn't set. 馃槥

This issue is still present on version 8.0.3. If you have the key prop on iOS drawer will be closed as soon as item is selected, not clicking on Done button.

@ArianHamdi yes, that was the problem. Initially in the code we were setting the value to the object that isn't in the list. Thank you.

Hi, Mine is not key prop issue, infact the key prop is not set.

But what i noticed is as follows:

if i set onValuechange prop to log to console it works but setting the value to state function fails .. drawer closes before clicking on done

Works:

<RNPickerSelect
            onValueChange={(val) => {
              console.log(val);
            }}
            placeholder={{label:"Select one", value:"Select one"}}
            value={data.state}
            style={pickerSelectStyles}
            items={states}
            Icon={() => {
              return <Icon size={20} name="ios-arrow-down" color={colors.black} />;
            }}
        />

Does not work:

<RNPickerSelect
            onValueChange={(val) => {
              setData({
                ...data,
                state: val,
              });
            }}
            placeholder={{label:"Select one", value:"Select one"}}
            value={data.state}
            style={pickerSelectStyles}
            items={states}
            Icon={() => {
              return <Icon size={20} name="ios-arrow-down" color={colors.black} />;
            }}
        />

I can confirm that getting rid of the key prop resolved my issue.

Same here key prop solved the issue

Was this page helpful?
0 / 5 - 0 ratings