Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android only: onValueChange not fired for placeholder item #604

Open
williamgurzoni opened this issue Jul 29, 2024 · 3 comments
Open

Android only: onValueChange not fired for placeholder item #604

williamgurzoni opened this issue Jul 29, 2024 · 3 comments

Comments

@williamgurzoni
Copy link

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: react-native-picker/picker#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

  • react-native-picker-select version: v9.1.3
  • react-native version: v0.73.8
  • @react-native-picker/picker: v2.7.7

Reproduction and/or code sample

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

@haoansonzeng
Copy link

same issue here

@mmanami-adc
Copy link

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

@MaxTibs
Copy link

MaxTibs commented Nov 5, 2024

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: react-native-picker/picker@243ead2

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants