jakezatecky/react-dual-listbox

Identify to movement of items from list

Closed this issue · 2 comments

I want to identify if the movement of selection happened from available to selected or selected to available.
I need to show some kind of notification and restrict movement from available to selected. but selected to available should work as it is

You should be able to identify movement via the onChange property. For example:

onChange(selected) {
  const oldSelected = this.state.selected;

  if (selected.length < oldSelected.length) {
    // Items removed from the selected list
  } else {
    // Items added from the available
  }
}

If you want to restrict movement, then you should probably add disabled: true to whatever options you have to the options property. You would likely need to make options a state variable in your container function/class to disable/enable at will.

Added controlKey parameter to the onChange function. Will be available in v2.4.0 release.