brimdata / react-arborist

The complete tree view component for React
MIT License
3.05k stars 139 forks source link

Deselect not firing event #224

Open samirotiv opened 8 months ago

samirotiv commented 8 months ago

On lines 341 to 345, there is a missing call to fire the tree.onSelect callback. This is preventing me from getting an updated list of selected nodes on deselection. I am using checkboxes for my implementation.

  deselect(node: Identity) {
    if (!node) return;
    const id = identify(node);
    this.dispatch(selection.remove(id));
  }

This needs to be:

  deselect(node: Identity) {
    if (!node) return;
    const id = identify(node);
    this.dispatch(selection.remove(id));
    safeRun(this.props.onSelect, this.selectedNodes);
  }
jakubbania94 commented 7 months ago

@jameskerr hey, can we get some attention here and merge a fix asap? This is a critical issue that needs to be solved.

It is reproducible on provided Demos, best visible on: https://react-arborist.netlify.app/cities on "Selected Items:" card counter

drmp13 commented 7 months ago

Up

msukmanowsky commented 5 months ago

Agree that this package should take care of this, but just noting that it's pretty easy to implement this when you have your own Node type:

function CustomNode({
  tree,
  node,
  style,
}: NodeRendererProps<MyCustomTreeItem>) {
  // You can access tree.props.onSelect and do tree.props.onSelect(tree.selectedNodes) after a deselect
}
goliney commented 2 months ago

Here is the bug demonstration:

https://github.com/user-attachments/assets/1aaa9ac7-b551-447d-9b75-556dce2f6985