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

Animation when internal node is opened and closed

Open piszczu4 opened this issue 2 years ago • 2 comments

Is it possible to add an animation when internal node is opened? Just to not show the children immidiately

Edit I manage to handle "open" case using react-spring but I cant figure out how to handle "close" case. Here is my code, https://codesandbox.io/s/usesimpletree-forked-yphp3t?file=/src/App.js

piszczu4 avatar Nov 11 '23 16:11 piszczu4

Close animations are very difficult in React. I have always wanted a way to add animation to this library. I believe there may be some opportunity with the view-transition api coming to browsers soon. But at the moment, I don't have a good answer for this.

Good luck!

jameskerr avatar Dec 12 '23 17:12 jameskerr

I achieved a similar visual effect without using additional packages or complicating things too much.

Opening and closing of a node increments / decrements the top property of all subsequent nodes. Any node element has a role of treeitem. As such I used pure CSS:

[role="treeitem"] {
  transition: top 0.05s ease-in;
}

It is not ideal, but looks fine.

ru13r avatar May 27 '24 23:05 ru13r