jakezatecky / react-dual-listbox

A feature-rich dual listbox for React.
https://jakezatecky.github.io/react-dual-listbox/
MIT License
109 stars 59 forks source link

Identify to movement of items from list #203

Closed secabhi closed 1 year ago

secabhi commented 1 year ago

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

jakezatecky commented 1 year ago

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.

jakezatecky commented 1 year ago

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