kenshoo / react-multi-select

A Multi Select component built with and for React
https://kenshoo.github.io/react-multi-select
MIT License
120 stars 53 forks source link

selectedItems not updating based on changes from state #156

Closed dannysun2 closed 5 years ago

dannysun2 commented 5 years ago

Expected Behavior

Removing names (state.options) from list via onclick results in a re-render should result in an updated selectedItems list to reflect the changes from the state.

https://github.com/dannysun2/react-multi-select

Jun-12-2019 16-51-43

Actual Behavior

While the component re-renders, the selectedItems list fails to reflect the new state changes.

Steps to Reproduce the Problem

  1. Click a name to remove from list
  2. Right side (selected items list) shows "6 Selected" however, the list still shows 7 selections.
liorheber commented 5 years ago

Hi @dannysun2 Thank you for your issue.

It seems that we've never implemented the component as a controlled component, meaning that the selectedItems is basically used for initialization at this point. I believe it would make a lot of sense to make the component work in a controlled state and I think the solution is quite simple if I'm honest.

I can't commit on a timeline at this point for a fix so I'd like to encourage you to contribute a solution to this. I think using a lifecycle method to update the selectedItems in the state in case that the selectedItems are defined and changed should most likely solve this.

Please let me know if you're interested in issuing a PR. Otherwise, I hope we can get someone on this a little later in the future.

Thanks again!

baptwaels commented 5 years ago

Controlled component feature implemented in #160

yegor-babiy commented 5 years ago

As fix was pushed , I close thread