Skip to content

react-json-tree request/question: classNames, getItemString state change on collapsed/expand #1090

Open
@braco

Description

@braco

It doesn't seem like it's possible to get the collapsed state of the current node within getItemString. Is this true?

The signature seems to be:

    <JSONTree
        ...
        getItemString={(type, data, itemType, itemString, keyPath) => <span>{itemType} {itemString}</span>}
    />

But without knowing the collapsed state, it's not possible to do something like this:

Collapsed
Screen Shot 2022-02-16 at 7 21 49 PM

Expanded
Screen Shot 2022-02-16 at 7 18 41 PM

which would increase legibility and allow for other use cases, like showing a stringified preview of the child content when collapsed.

Some of the above and more could be helped with classNames that change based on the state of the node.

If there was a theme convention like:

nestedNode: className
nestedNodeCollapsed: className
nestedNodeTypeArray: className

The layout could changed based on the node state. I tried to hack my way through some layout changes, but there's no way to accomplish some of these things without having access to the state.

Screen Shot 2022-02-16 at 11 33 55 PM

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions