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

Selecting the placeholder item causes a crash/duplicate placeholder items

Open ylac opened this issue 7 years ago • 6 comments

Describe the bug
The app crashes if you select the placeholder item after selecting another item.

This occurs regardless of whether a placeholder is provided.

Adding an item object with value: null results in duplicate placeholder items appearing in the dropdown.

To Reproduce

Crash

  1. Select a non-placeholder item
  2. Select the placeholder item
  3. See error: TypeError: TypeError: Cannot read property 'label' of undefined.

  1. Add an item object with a value of null to the items array.

Expected behaviour
The placeholder item should just be selected. There should only be one placeholder item.

Screenshots
See below.

Smartphone (please complete the following information):

  • Device: Samsung S6
  • OS: Android 7.0
  • react-native-picker-select version: 6.0.0
  • react-native version: 0.55
  • react version: 16.3.1

Reproduction and/or code sample

Crash

      const items = [
           {
              label: 'Packed By Owner',
              value: 'packed_owner'
           }
       ]
      <RNPickerSelect
        items={items}
        onValueChange={onChange}
        value={value}
      />

Duplicate placeholders

const items = [
           {
               label: 'Select items...',
               value: null
           },
           {
              label: 'Packed By Owner',
              value: 'packed_owner'
           }
       ]

screenshot_20190225-162208

ylac avatar Feb 25 '19 05:02 ylac

So you’re passing a placeholder in to the items array? Any reason you’re not using the placeholder prop?

lfkwtz avatar Feb 25 '19 12:02 lfkwtz

If I use the placeholder prop, and select a non-placeholder item, then the placeholder item, I trigger an exception as described above.

ylac avatar Feb 25 '19 21:02 ylac

Can you produce a reproduction on snack.expo.io?

lfkwtz avatar Feb 25 '19 22:02 lfkwtz

@ylac

lfkwtz avatar Mar 05 '19 20:03 lfkwtz

Can't repro, closing thanks.

ylac avatar Mar 05 '19 22:03 ylac

I faced with the same problem, I downgraded react native version to 0.63.0, it resolved the problem

cherkanovart avatar May 04 '21 18:05 cherkanovart