lawnstarter / react-native-picker-select

🔽 A Picker component for React Native which emulates the native <select> interfaces for iOS and Android
https://npmjs.com/package/react-native-picker-select
MIT License
1.74k stars 499 forks source link

Select View Closes When Value Changes #409

Open dioncodes opened 3 years ago

dioncodes commented 3 years ago

Describe the bug
The select popup closes instantly when the state and selected value changes. If the value isn't changed, it will jump back to the specified option of the value property .

To Reproduce
Steps to reproduce the behavior:

  1. Tap select
  2. Scroll to a different option (iOS)
  3. Select View disappears

Expected behavior
Select View should stay present until it is closed or "done" is tapped.

Screenshots
n/a

Additional details

Reproduction and/or code sample

<RNPickerSelect
    onValueChange={(value: number) => {
        setSelectedValue(value);
    }}
    items={[
        { label: 'Test A', value: 0 },
        { label: 'Test B', value: 1 },
        { label: 'Test C', value: 2 },
    ]}
    value={selectedValue}
/>
lfkwtz commented 3 years ago

fill out full bug report

radabo commented 3 years ago

I have same problem :-(

dioncodes commented 3 years ago

fill out full bug report

What do you mean? I filled out the github issue bug template.

lfkwtz commented 3 years ago

additional details aren't filled out

dioncodes commented 3 years ago

additional details aren't filled out

Sorry, I've added the missing version numbers of the additional details above.

dbazian commented 3 years ago

Same problem here

EmmanuelSkapple commented 3 years ago

Same problem to :/

dioncodes commented 3 years ago

I managed to find a temporary workaround until this is fixed:

useEffect(() => { picker.current?.setState({ selectedItem: { label: 'Example B', value: 1 } }); }, []);



Please note that the full item (including label) needs to be passed, not only the value.