brimdata / react-arborist

The complete tree view component for React
MIT License
2.96k stars 134 forks source link

Have ability to set the scrollTop directly to Tree ref #194

Open thomas-le183 opened 9 months ago

thomas-le183 commented 9 months ago

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?

jameskerr commented 8 months ago

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

vulevukusej commented 5 months ago

Also interested :)

vulevukusej commented 5 months ago

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);
            }
        };
    }, []);