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

Not able to select Number values since @react-native-picker/picker upgrade to 2.6.1 #530

Open
fahad86 opened this issue Dec 1, 2023 · 9 comments

Comments

@fahad86
Copy link

fahad86 commented Dec 1, 2023

Describe the bug

If value is a number, then it always defaults to the first item

Issue started happening after upgrading peer dependancy: @react-native-picker/picker to version 2.6.1

To Reproduce

change values to numbers

Expected behavior

Value selected should change when using the picker

Screenshots

n/a

Additional details

  • Device: iPhone8
  • OS: 17
  • react-native-picker-select version: 9.0.0
  • react-native version: 0.72.7
  • expo sdk version: n/a
  • @react-native-picker/picker: 2.6.1

Reproduction and/or code sample

@fahad86 fahad86 changed the title Not able to select Number values Not able to select Number values since @react-native-picker/picker tupgrade to 2.6.1 Dec 1, 2023
@fahad86 fahad86 changed the title Not able to select Number values since @react-native-picker/picker tupgrade to 2.6.1 Not able to select Number values since @react-native-picker/picker upgrade to 2.6.1 Dec 1, 2023
@wesleyvandevoorde
Copy link

We are having the same issue, also objects as values don't seem to work. Only strings are working

@karo-dc
Copy link

karo-dc commented Jan 12, 2024

Same here, any update?

@joeldebont
Copy link

I'm having the same issue on react-native 73.2.

@zabojad
Copy link

zabojad commented Jan 19, 2024

Has anyone found a solution?

@dpatra
Copy link

dpatra commented Feb 10, 2024

Any Solutions please

@zabojad
Copy link

zabojad commented Feb 12, 2024

use strings only with picker and convert them to numbers when needed...

@girardinsamuel
Copy link

I experienced the same issue !
I will convert values to strings in the meantime.

@andrejpavlovic
Copy link

Seems issue originates from here: react-native-picker/picker#538

@hardchopshoppirate
Copy link

hardchopshoppirate commented Mar 26, 2024

Temporary solution: create a wrapper component that converts a value (if it is a number) to a string, then back to the original type. Cannot use prev version due to expo 50 complains. That is the only way it may work for me :(

Pseudocode below:

type SelectProps = {
  value: string | number;
  options: { value: string | number; label: string };
  onChange: (value: any) => void;
}

const Select = ({ selectedValue, options, onChange }) => {
  const originalValueType = useRef(
    detectType(value),
  );

  const valueString = String(selectedValue);
  const options = options.map((item) => ({ label: item.label, value: String(item.value) }));
  const handleChange = (value: any) => {
    onChange(
      convertToType(value, originalValueType),
     );
  };

  return (
    <RNPickerSelect
      value={valueString}
      items={options}
      onValueChange={handleChange}
    />
  );
}

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

9 participants