react-native-picker-select icon indicating copy to clipboard operation
react-native-picker-select copied to clipboard

Select View Closes When Value Changes

Open dioncodes opened this issue 4 years ago • 8 comments

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

  • Device: Simulator (iPhone 11, 12 Pro, etc.)
  • OS: iOS 14.3
  • react-native-picker-select version: 8.0.4
  • react-native version: 0.63.4
  • expo sdk version: n/a

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

dioncodes avatar Jan 10 '21 16:01 dioncodes

fill out full bug report

lfkwtz avatar Jan 11 '21 13:01 lfkwtz

I have same problem :-(

radabo avatar Jan 12 '21 14:01 radabo

fill out full bug report

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

dioncodes avatar Jan 12 '21 15:01 dioncodes

additional details aren't filled out

lfkwtz avatar Jan 12 '21 15:01 lfkwtz

additional details aren't filled out

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

dioncodes avatar Jan 12 '21 15:01 dioncodes

Same problem here

dbazian avatar Jan 18 '21 19:01 dbazian

Same problem to :/

EmmanuelSkapple avatar Jan 19 '21 16:01 EmmanuelSkapple

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

  • Remove the value prop from the <RNPickerSelect />
  • Use a ref (<RNPickerSelect ref={picker} ... />) and set the initial value (using setState) at the beginning:
const picker = useRef<RNPickerSelect>(null);

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.

dioncodes avatar Jan 29 '21 18:01 dioncodes