-
-
Notifications
You must be signed in to change notification settings - Fork 94
Expand without select #289
-
Is it possible to expand a node without also selecting it?
I see in all of the examples from playground and storybook (and in my implementation) that when you expand an item you also select it.
I am using the "click-arrow-to-expand" interaction mode, so there is no click on the actual tree item.
Beta Was this translation helpful? Give feedback.
All reactions
Thank you for the reply. Your notes made me dive deeper and i actually went another route for this as i was also using renderItemArrow
.
I noticed that the onClick
from arrowProps has an actions.selectItem()
by default (https://vscode.dev/github/lukasbach/react-complex-tree/blob/main/packages/core/src/treeItem/useTreeItemRenderContext.ts#L187-L188). I just changed that implementation to:
renderItemArrow={({ item, context }) => renderItemIcons( item, { ...context, arrowProps: { ...context.arrowProps, onClick: () => context.toggleExpandedState() } } )}
Replies: 1 comment 1 reply
-
If you just want to expand an item programmatically, there is a expandItem
method on the item reference, and also one on the tree environment reference that takes an item id and tree id.
But if you want to completely customize the default behavior for what happens when the user clicks on an item, you can implement an custom interaction mode: https://rct.lukasbach.com/docs/guides/interaction-modes#custom-interaction-modes
Since you are using the click arrow to exapnd interaction mode, you can copy its implementation and adjust it to your needs: https://github.com/lukasbach/react-complex-tree/blob/main/packages/core/src/interactionMode/ClickArrowToExpandInteractionManager.ts
It should probably work to just remove all action.xx calls that do something with selections from there.
Beta Was this translation helpful? Give feedback.
All reactions
-
Thank you for the reply. Your notes made me dive deeper and i actually went another route for this as i was also using renderItemArrow
.
I noticed that the onClick
from arrowProps has an actions.selectItem()
by default (https://vscode.dev/github/lukasbach/react-complex-tree/blob/main/packages/core/src/treeItem/useTreeItemRenderContext.ts#L187-L188). I just changed that implementation to:
renderItemArrow={({ item, context }) => renderItemIcons( item, { ...context, arrowProps: { ...context.arrowProps, onClick: () => context.toggleExpandedState() } } )}
Beta Was this translation helpful? Give feedback.