Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Expand without select #289

Discussion options

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.

You must be logged in to vote

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

Comment options

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.

You must be logged in to vote
1 reply
Comment options

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() } } )}

Answer selected by bogdancalmutchi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /