Add some getter for the "open" property of each node
The open property (well, collapsed actually) is part of my controlled data.
I want it to be like this so that the open or closed state is persistent.
I've tried using the onToggle property to keep my open state in sync with react-arborist's open, and it seems to work fine. The problem is that with the initial state they become desynchronized. openByDefault to true or false would not solve my problem, because some nodes should be able to be initialized open and others closed.
Two ideas have occurred to me:
- Add an
openAccessororgetOpenprop that works as a getter and useonToggleas a setter. - Add two properties
getOpenandsetOpen. It probably makes sense to deprecateonTogglein this case.
Something I don't like about onToggle is that instead of passing the node, it passes the id, and I have to do a lookup of my data to find it and access it.
Edit: I just discovered the initialOpenState property that I had overlooked.
With this I have been able to solve it, although it is a bit of a boilerplate since I have to go through my entire data structure and form an OpenMap, not ideal.
You're right. This is not ideal. I am considering changing the api to make this easier in the next major version. Glad you were at least able to create a workaround.
any update on this ?
I would be also appreciated for the change the API to: onToggle?: (node: NodeApi<T>) => void