BelkacemYerfa / shadcn-extension

An open source component collection , that extends your ui library , built using shadcn component
https://shadcn-extension.vercel.app/
MIT License
459 stars 15 forks source link

Tree view expandedItems state not update correctly #41

Open n3mooo opened 2 months ago

n3mooo commented 2 months ago

Reproduction link

https://shadcn-extension-landing.vercel.app/docs/tree-view

Steps to reproduce

  1. Render the Icon button in the correct state by passing the state out with the param function // ./tree-view-api.tsx -> CollapseButton

image

  1. Click Expand button and then click option open on root Folder and close, you will see a undefine value in array expandedItems state

What is expected?

It work properly, the state setExpandedItems should update correctly

n3mooo commented 2 months ago

I found the cause and fixed it with the code below Just checked the value, make sure it's the safe value when insert to the array Tree

image

BelkacemYerfa commented 2 months ago

Hello @n3mooo Thanks for pointing out this issue, if i understand correctly you want to render the proper icon in the Collapse button based on the state of the Tree element, for example : <CloseIcon /> if the Tree is not expended , otherwise a <OpenIcon />. And as i see from the first code snippet , you have made some sort of a custom function called renderChildren for that case.

If you could share with us a codesandbox sample for this bug that you have faced , that would be more helpful , since we don't have enough informations to do the proper fix.