-
Notifications
You must be signed in to change notification settings - Fork 18
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
Feature Request: Add prop to allow initially collapsed #39
Comments
Doesn't |
Sorry for the late response... Can you please describe what do you mean by "interaction"? Is it just click on the root node, or scroll on the page to the component until it is visible? const [expanded, setExpanded] = React.useState(false);
<button className={cx('button')} onClick={() => setExpanded(!expanded)}>
{expanded ? 'Collapse' : 'Expand'}
</button>
<JsonView
data={jsonData}
shouldExpandNode={expanded ? expandFirstLevel : collapseAllNested}
style={defaultStyles}
/> I think it will be less convenient for the user comparing to the simple click on the root node but still will work. |
Sorry, I missed @fabiradi comment in November. Yes, I would like to set initial state fully closed, with ability to click on the arrows to expand the nest. @AnyRoad 's workaround does this (with slight modification), but is clunky with the extra button. My example, is a logger with many, many objects. They need to be closed initially because the objects are large. End users choose to expand objects only when they are debugging: It would be nice if the library didn't require the workaround. It's confusing to end users that they can't click on the arrow. It's a good library with a lot of downloads. I'm surprised my use case isn't more common ¯\(ツ)/¯ |
It's great that you can click on the tree nodes to expand them, but I'd like a way to specify that the tree should be initially collapsed (my use case is a log viewer with lots of objects in a big scrollable list).
In other words, I'd like to collapse the tree until the end user interacts with it.
I don't think there's a way to accomplish this with shouldExpandNode function, but I think you could add another prop called
initialExpansionLevel
to make this easy to control.The text was updated successfully, but these errors were encountered: