expand/collapse all nodes with useTreeState #3730
-
I added 2 Buttons in my tree-view based on This is my code:
Button-Code (Chakra-UI):
Unfortunately this does not work (only 1 node gets expanded. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
If I recall correctly, state.collection will only have the "visible" keys since it's a collection and could theoretically have a lot of nodes, far more than you'd want rendered, non-visible nodes aren't included in the collection until their parents are expanded. You could add all the keys to the expanded keys set though and pass that in as a prop to useTreeState, thereby controlling the expanded states. You could also use defaultExpanded if you didn't want to make it controlled. |
Beta Was this translation helpful? Give feedback.
If I recall correctly, state.collection will only have the "visible" keys since it's a collection and could theoretically have a lot of nodes, far more than you'd want rendered, non-visible nodes aren't included in the collection until their parents are expanded. You could add all the keys to the expanded keys set though and pass that in as a prop to useTreeState, thereby controlling the expanded states. You could also use defaultExpanded if you didn't want to make it controlled.