Skip to content

Add some getter for the "open" property of each nodeΒ #207

@GermanJablo

Description

@GermanJablo

The open property (well, collapsed actually) is part of my controlled data.

I want it to be like this so that the open or closed state is persistent.

I've tried using the onToggle property to keep my open state in sync with react-arborist's open, and it seems to work fine. The problem is that with the initial state they become desynchronized. openByDefault to true or false would not solve my problem, because some nodes should be able to be initialized open and others closed.

Two ideas have occurred to me:

  • Add an openAccessor or getOpen prop that works as a getter and use onToggle as a setter.
  • Add two properties getOpen and setOpen. It probably makes sense to deprecate onToggle in this case.

Something I don't like about onToggle is that instead of passing the node, it passes the id, and I have to do a lookup of my data to find it and access it.

Edit: I just discovered the initialOpenState property that I had overlooked.
With this I have been able to solve it, although it is a bit of a boilerplate since I have to go through my entire data structure and form an OpenMap, not ideal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions