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

Have ability to set the scrollTop directly to Tree ref

Open thomas-le183 opened this issue 2 years ago • 3 comments

Hello, I'm currently employing react-arborist for my Gantt chart. This library has a unique approach that restricts my ability to manipulate the Tree DOM, including setting the scrollTop property. Is there a way to synchronize scrolling between two different div elements in this context?

thomas-le183 avatar Nov 26 '23 05:11 thomas-le183

You're right. It's not possible today. I'll consider adding this ability in a future release.

jameskerr avatar Dec 12 '23 17:12 jameskerr

Also interested :)

vulevukusej avatar Apr 03 '24 14:04 vulevukusej

My workaround in case anyone is interested (so far it works nicely):

function customScrollHandler(e: Event) {
     const target = e.target as HTMLElement;
     useGanttScroll.setState({ scrollPositionY: target.scrollTop });
 }
 
 useEffect(() => {
     const treeDiv = document.querySelector('[role="tree"]');
     if (treeDiv) {
         const child = treeDiv.firstChild as HTMLDivElement;
         child.addEventListener("scroll", customScrollHandler);
     }
 
     return () => {
         if (treeDiv) {
             const child = treeDiv.firstChild as HTMLDivElement;
             child.removeEventListener("scroll", customScrollHandler);
         }
     };
 }, []);

vulevukusej avatar Apr 04 '24 08:04 vulevukusej