Skip to content

Collapse events and setting collapse #145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Jack-skitt opened this issue Jan 6, 2025 · 4 comments
Closed

Collapse events and setting collapse #145

Jack-skitt opened this issue Jan 6, 2025 · 4 comments
Labels
enhancement New feature or request user request Requested by user

Comments

@Jack-skitt
Copy link
Contributor

Hi,

Is it possible to have a onCollapse event, or be able to set which nodes are collapsed, what we are trying to do is save which nodes are expanded so when the user comes back to the page they won't have to re expand the tree to where they left off?

@CarlosNZ CarlosNZ added enhancement New feature or request user request Requested by user labels Jan 6, 2025
@CarlosNZ
Copy link
Owner

CarlosNZ commented Jan 6, 2025

Good suggestion, and should be fairly easy to implement. I'll have a play around and keep you posted.

@CarlosNZ
Copy link
Owner

Hi @Jack-skitt, sorry for the slow progress on this. Just thinking about it -- I can easily at an onCollapse event, but not sure that would be enough for your use case. You'll be able to record the state of nodes as they are collapsed/expanded, but I'm not sure how you'd restore them all when reloading. Or were you thinking we could add a mechanism to trigger collapse/expand from outside the component as well?

@CarlosNZ
Copy link
Owner

Hi @Jack-skitt -- I have made an initial version of this functionality and have a beta available if you'd like to try it out: https://www.npmjs.com/package/json-edit-react/v/1.25.0-beta1

See the documentation for "External control" for how to implement it.

Hopefully it works for you, though completely capturing the collapse state and re-initialising it might be a bit too complex -- let me know how it goes, and if you have any suggestions for improvement before I make an official release.

@CarlosNZ
Copy link
Owner

Done in #182 and released in v1.25.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request user request Requested by user
Projects
None yet
Development

No branches or pull requests

2 participants