fateh999 / react-native-paper-dropdown

Dropdown using react native paper TextInput and Menu
121 stars 72 forks source link

Unselect in multiselect is not being return by setValue #92

Closed leons1767 closed 1 year ago

leons1767 commented 1 year ago

Using Expo SDK46 with RN0.69.9 running on expo development client

                    <DropDown
                        dropDownContainerMaxHeight={300}
                        label={placeholder}
                        mode='outlined'
                        visible={showDropDown}
                        showDropDown={() => setShowDropDown(true)}
                        onDismiss={() => setShowDropDown(false)}
                        value={value}
                        setValue={setValue}
                        list={dropDownList}
                        inputProps={{disabled}}
                        multiSelect
                    />

I tried console.log in setValue prop, and it always returns the previous selected value, without removing the unselected value. It will add the additional selected value from the multiSelect, but it doesn't remove unselected value.

leons1767 commented 1 year ago

Checked the codes in DropDown.js, and found the problem.

In my case, the dropDownList has value as number type, and the original code does not support number.

To support number, change from: onChangeValue([...values].filter((value) => value !== currentValue).join(","));

to: onChangeValue([...values].filter((value) => value !== currentValue.toString()).join(","));