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

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

Open fahad86 opened this issue 1 year ago • 9 comments

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 avatar Dec 01 '23 02:12 fahad86

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

wesleyvandevoorde avatar Dec 21 '23 08:12 wesleyvandevoorde

Same here, any update?

karo-dc avatar Jan 12 '24 11:01 karo-dc

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

joeldebont avatar Jan 15 '24 13:01 joeldebont

Has anyone found a solution?

zabojad avatar Jan 19 '24 15:01 zabojad

Any Solutions please

dpatra avatar Feb 10 '24 09:02 dpatra

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

zabojad avatar Feb 12 '24 11:02 zabojad

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

girardinsamuel avatar Mar 08 '24 15:03 girardinsamuel

Seems issue originates from here: https://github.com/react-native-picker/picker/issues/538

andrejpavlovic avatar Mar 12 '24 12:03 andrejpavlovic

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

hardchopshoppirate avatar Mar 26 '24 13:03 hardchopshoppirate