fateh999 / react-native-paper-dropdown

Dropdown using react native paper TextInput and Menu
MIT License
130 stars 74 forks source link

Fixes bug in multiselect dropdown selection #44

Closed mfitzer closed 1 month ago

mfitzer commented 2 years ago

Expected Behavior:

When I select an option in a multiselect question, I expect only that option's selection state to be changed.

Actual Behavior:

If there are two options, "Option A" and "Option AB", and I select "Option AB", the multiselect component will display both options as selected, even though only one option was selected. Also, if "Option AB" is selected, "Option A" cannot be unselected.

Steps to Reproduce:

  1. Pass in the following list of options:
    [
    { label: "Cheese, meat, and crackers", value: "Cheese, meat, and crackers" },
    { label: "Cheese and crackers", value: "Cheese and crackers" },
    { label: "Cheese", value: "Cheese" }
    ]
  2. Select either of the first two options
  3. Note the following:
    • The display value and selected options include the last option
    • The last option cannot be deselected while one of the first two options is selected

Cause:

string.indexOf() is being called on the csv value string looking for each option to see if it is active. This fails when one option is a substring of another option.

Solution:

Change methods to first split the csv value string into an array of values and then call indexOf on that array instead. This results in a strict comparison with each value that prevents the described issue.

jeffreyvanhees commented 2 years ago

Running into the same bug. @fateh999, any idea if and when this will be merged?

RiedelNicolas commented 1 year ago

I think the project is dead. Best option is to fork.