mac-s-g / react-json-view

JSON viewer for react
https://mac-s-g.github.io/react-json-view/demo/dist/
MIT License
3.42k stars 531 forks source link

collapsed property not overriding manual expand/collapse. #166

Open dyennam opened 6 years ago

dyennam commented 6 years ago

Hello, in the demo i have set COLLAPSED = 1. Then expand the ARRAY object. After expansion I try to modify the COLLAPSED = 2, this causes the rest of the object to expand to same depth as ARRAY (Which is expected). But once i set the COLLAPSED = 1, the rest collapse but the ARRAY object stays expanded. My end goal is to have a expand and collapse button that work even if the user has manually expanded / collapsed I have attached a image of my settings. image

mac-s-g commented 6 years ago

@dyennam thank you for brining this up.

when a user clicks to expand or collapse, expand/collapse state is introduced within RJV. this is intentional given the way the component is currently designed. that is - you can define the default state for expand/collapse, but the user takes over from there.

an alternative would be that RJV handles no expand/collapse built-in functionality; but instead throws a callback when a user clicks to expand or collapse. the HOC would then choose to act on that callback or not. It would also be up to the HOC to manage the expand/collase state. this implementation would requore a bit more heavy lifting for users, but it would offer more control.

I see pro's and con's to both approaches - I could consider adding more expand/collapse props to give users more control over behavior.

I'm honestly a bit surprised this is the first time your request has come up. I'm going to label this as discussion for now and see if the community has any opinion.

dyennam commented 6 years ago

@mac-s-g Thanks for the quick reply.

It would be nice, if we could have a bool overrideManualCollapse prop, such at we can have a value that forces external actions to override the default behavior. Such as if overrideManualCollapse is true, the collapsed property will get passed to all elements irrespective of if the user has touched the ui manually or not. This way RJV will handle expand/collapse as its doing it now, but if the user need to override expand/collapse every time, we pass the prop directly to the HOC, and that trickles down. (Hopefully what I said is comprehensible.)

nitishdhar commented 2 years ago

Being able to override user defined state seems a common use case e.g. an interface wants to enable user to handle specific collapse states but also lets the user to reset things to either collapse all or expand all.

What would be a workaround for this with the current state of things?