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

itemKey doesn't work #580

Open
saaspeter opened this issue May 23, 2024 · 2 comments
Open

itemKey doesn't work #580

saaspeter opened this issue May 23, 2024 · 2 comments

Comments

@saaspeter
Copy link

saaspeter commented May 23, 2024

Describe the bug

according to the document: "Will attempt to locate a matching item from the items array by checking each item's key property". but in my testing in IOS, it don't work, but when I change itemKey to value field, it works. (the key and value are same value in my data)

To Reproduce

Steps to reproduce the behavior:

  1. set itemKey = 1 in code
  2. in UI, open the picker, then select the second item, press done.
  3. reopen the picker, found the selected item is still on the second item

Expected behavior

I expect the selected items in the above steps should be the first item(with key=1, also value=1).
when I change the itemKey to value field, it works, everytime reopen the picker, the selected item always be the first.

according to the document, in IOS we should use itemKey, but it seems the value property works and itemKey don't work.

Screenshots

Add screenshots to help explain your problem. If screenshots aren't applicable to this issue, write "n/a".

Additional details

  • Device: [e.g. iPhone12]
  • OS: iOS17.4
  • react-native-picker-select version: ^9.1.3

Reproduction and/or code sample

<RNPickerSelect
onValueChange={(value) => setTimesADayValue(value)}
itemKey={1}
items={ BizType.getTimesADayArray() }
ref={Platform.OS === 'ios' ? pickerRef2 : null}
pickerProps={{ ref: Platform.OS === 'android' ? pickerRef2 : null }}
style={pickerSelectStyles}
useNativeAndroidPickerStyle={false}
onDownArrow={()=>null}
/>
my data items like this:
const timesADayArray = [{label: 'one time a day', value: 1, key: 1}];
for (let j = 2; j <= 12; j++) {
timesADayArray.push({label: j+' times a day', value: j, key: j},);
}

when I change itemKey field to 'value' field, it works.

@athul-22
Copy link

athul-22 commented Jun 9, 2024

#586

Please check this PR

@saaspeter
Copy link
Author

@athul-22 , thank you, I will try this new updates. (currently I am using 'value', it works well :) )

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

2 participants