react-arborist icon indicating copy to clipboard operation
react-arborist copied to clipboard

childrenAccessor property doesn't work

Open iq-developer opened this issue 1 year ago • 5 comments

When I try to use child elements with another name than "children" there are some bugs:

  1. not possible to move elements without children
  2. when we put element with children as a child element of element without children, first one disappear

Example: https://codesandbox.io/s/the-simplest-tree-forked-2ko6gl?file=/src/App.tsx

Both options doesn't work properly:

  • childrenAccessor="elements"
  • childrenAccessor={(node) => node.elements}

@jameskerr Please provide a working example of tree that have Data with Different Property Names

iq-developer avatar Nov 25 '22 13:11 iq-developer

You're right. This is a bug. The useSimpleTree hook needs to be updated to accept childrenAccessor props and idAccessor props.

jameskerr avatar Nov 28 '22 23:11 jameskerr

The bug is with initialData. If you use the data prop, and provide your own handlers, the childrenAccessor will work.

The workaround for now is to change your data before passing it to react-arborist.

jameskerr avatar Nov 28 '22 23:11 jameskerr

@jameskerr I like your library and I would like to use it with childrenAccessor feature. So I can try to updated useSimpleTree hook and make a Pull request. How can I install react-arborist for development? (not as a library)

iq-developer avatar Dec 05 '22 17:12 iq-developer

Yes, that would be welcome. Clone the Repo then run yarn && yarn dev. That will watch for changes to the code and will start the demo site at localhost.

jameskerr avatar Dec 05 '22 23:12 jameskerr

Too complex :( I will wait for your help with fixing this bug

iq-developer avatar Dec 06 '22 17:12 iq-developer