I'm working on a TreeView component, and I find myself writing a whole lot of code to circument a rather simple problem arising from the use of React-DnD.
Case in point: when navigating the tree view with the up and down arrow keys, the node that should be selected is not always the successor or predecessor on the same level. For example, when moving up and the same-level predecessor is open and has children, usability dictates (to me at least) that the predecessor's last child should be selected (or actually, the last visible descendant), since that is visually the immediate predecessor of the previously selected node.
The problem occurs when trying to determine if the predecessor's descendant (let's call it the "target" node) is open or closed. That information is being maintained in the target node's state.
And that's where the problem is: the component I created to represent the nodes is wrapped by a React-DnD DragSource
. But while the wrapping mechanism of React-DnD gives transparent access to a wrapped component's properties, that is not the case for its states: DragSource exposes its own states, but does not give access to the states of the component it wraps.
Combined with the fact that the wrapper intercepts callback ref
s of wrapped components so as to pass its own instances instead of the wrapped ones, that means that I simply cannot access the open/closed state of my nodes, even thoughn I know exactly where they are positionally. (And actually, I did have this working perfectly before I started using React-DnD.)
How can I deal with this situation? Could this be a bug or oversight of React-DnD, or is there a way to get access to the wrapped component that I don't know of?
Note: there seems to be a method to access the wrapped component, but the doc states that that is intended for testing.