react-native-picker / picker

Picker is a cross-platform UI component for selecting an item from a list of options.
MIT License
1.47k stars 277 forks source link

`onValueChange` type for the web picker is wrong #464

Open trevorzablocki2 opened 1 year ago

trevorzablocki2 commented 1 year ago

The type for the onValueChange prop of the web picker is set to the following (here):

  onValueChange?: (number | string, number) => void,

but the value coming back from the event for the option components are always strings. It seems like these returned values should be parsed to the correct type based on the passed in option values or this type should just indicate it will only be a string.

almirfilho commented 5 months ago

I'm also having the same issue. I got this regression after upgrading to version 2.6.1 (I was previously on version 2.4.10). iOS only. Android still works as expected.

Reproducible snippet:

<Picker onValueChange={value => console.log('changed', value, typeof value)}>
  <Picker.Item label='One' value={1}/> // outputs -> changed "1" string
  <Picker.Item label='Two' value={2}/> // outputs -> changed "2" string
</Picker>
MoOx commented 4 months ago

Getting this issue as well. It might need a tiny change in https://github.com/react-native-picker/picker/blob/7b7a95f4fe842d0a0c696310f9f10a8267247227/js/Picker.web.js#L59 somehow by checking initials values send using Picker.Item