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.76k stars 499 forks source link

Android only: onValueChange not fired for placeholder item #604

Open williamgurzoni opened 3 months ago

williamgurzoni commented 3 months ago

Describe the bug
After updating @react-native-picker/picker to version v2.7.7 the onValueChange event stopped working when the user presses the placeholder item. This is an Android only issue.

The issue was cause by this PR: https://github.com/react-native-picker/picker/pull/571

To Reproduce
Steps to reproduce the behavior:

  1. Create a dropdown with a placeholder
  2. Test on iOS, the event is fired when the placeholder item is selected
  3. Test on Android, the event is not fired when the placeholder item is selected

Expected behavior
The onValueChange event should be fired consistently in both platforms when the user selects the placeholder item.

Screenshots
N/A

Additional details

Reproduction and/or code sample
https://snack.expo.dev/@gurzoni/issue-rnpickerselect---android-not-firing-onvaluechange-for-placeholder-item?platform=android

haoansonzeng commented 2 months ago

same issue here

mmanami-adc commented 1 month ago

Same for me, haven't found a workaround yet since the action is not being triggered at all

MaxTibs commented 1 week ago

I've got this issue after upgrading the library from 9.0.1 to 9.3.1. The difference in my case is that I do not use the placeholder, I actually removed it by passing placeholder={{}}. One of my item have a value of 0 and I cannot select it because of the change made here: https://github.com/react-native-picker/picker/commit/243ead2e226ea5441a7091beccc903e804922c18

const value = children[position]?.props?.value;
if (value) {
  onValueChange(value, position);
}

The code is not calling onValueChange for values that are considered false in Javascript: false, "", null, undefined, 0, etc

Not sure why this change was necessary, IMO it's up to the developer to interpret the value returned by the picker. If null is meant to represent the placeholder value, than it should be the developer responsibility to handle that null value from it's onValueChange handler. I don't think the values should be muted from within the picker implementation.

So in other words, this bug should be transferred to the react-native-picker/picker project