react-treebeard icon indicating copy to clipboard operation
react-treebeard copied to clipboard

Unable to set node active state separately from toggling

Open jwbay opened this issue 8 years ago • 4 comments

For a folder selection treeview, we need to be able to split 'selecting' a node from expanding/collapsing it. I got 95% of the way there by implementing a Container decorator that composes Header and Toggle, but I hit a brick wall because of this:

    renderHeader(decorators, animations){
        return (
            <NodeHeader
                ...
                node={Object.assign({}, this.props.node)}
                ...
            />
        );
    }

The NodeHeader doesn't get a handle on the node object proper, presumably to prevent mutations, but that means my Header decorator can't set node.active. It looks like changing the node can only be done via calling through to onClick, which calls through to onToggle with no way to represent that it should actually select instead of toggling.

jwbay avatar May 26 '16 15:05 jwbay

If you're interested I fixed it in a forked branch, it's one commit so far. I didn't look into the required tests, but it's a start.

riquito avatar May 30 '16 21:05 riquito

This would be a neat feature @alexcurtis

hannupekka avatar Jun 06 '16 06:06 hannupekka

PR: https://github.com/alexcurtis/react-treebeard/pull/51

goodmorninggoaway avatar Dec 12 '16 21:12 goodmorninggoaway

You can solve this with the existing library via a custom Header that sets an onClick handler on the expand/collapse icon and stops the event from propagating to onToggle via event.stopPropogation().

cdtinney avatar May 17 '18 14:05 cdtinney