react-arborist
react-arborist copied to clipboard
Tree.onSelect
It might be cleaner to have an onSelect callback that can be placed on the root tree node. It only get's fired when an item gets selected. A group can only be selected during multi select.
New Api:
type TreeProps = {
onSelect: () // only get's called when a single item is selected.
}
Then when the tree selects something programmatically, this code can run and does not need to be duplicated.
This makes it easy for the click handlers too. We can have a default handlers.click function that checks if it's an item and runs on select, or checks if it's a folder and runs toggle.
<div onClick={handlers.onClick}>
We should prefix all the handlers with on so that you don't forget them.
This is actually not the way to go, closing.
This is actually not the way to go, closing.
Why not?
I am still trying to figure out how to trigger an event on node select. It's not obvious at all.
I have a prop that contains a function that I want to call. onSelect(({data}) => {})
feels the most natural.
I'll reopen this then. Yeah, I can't think of an easy way to run a function when the node is selected. You'd have to put that code in the onClick handler of NodeRenderer probably, which is not very natural.
+1 for this, first thing I was looking out was the onSelect handler from the Tree.