react-arborist
react-arborist copied to clipboard
Have ability to set the scrollTop directly to Tree ref
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?
You're right. It's not possible today. I'll consider adding this ability in a future release.
Also interested :)
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);
}
};
}, []);