Thanks for the great lib. I have a use case where I'm building a spreadsheet-like application. It's a flowchart editor but constrained to a grid, you can see it here. I need to overlay some elements such that they line up with cells in the grid. For example, to edit the text in a cell I render a <textarea /> absolutely positioned over the underlying cell. It needs to be perfectly aligned to preserve the illusion that you're directly editing the text in the cell. I also have to render some svg lines between nodes in the flowchart, etc. When scrolling the overlay items also need to stay positioned correctly relative to the cells.
I'm currently achieving this (see link above) through a hack of getting a ref to FixedSizeGrid's innerRef and then using React.createPortal to render the overlay elements into the same parent container as the cells. This gives the overlay items the same origin as the cells so they line up by default. This works, but of course is a hack and depends on some assumptions about the internals of react-window.
My question is: Is there a more standard approach to this? I have seen discussions using ScrollSync, which I tried to implement without much success. There was too much lag / perf issues. I thought about modeling the overlay elements as grid items themselves but couldn't quite figure this out, especially for the <svg> element that renders the lines between nodes.
Thanks for the great lib. I have a use case where I'm building a spreadsheet-like application. It's a flowchart editor but constrained to a grid, you can see it here. I need to overlay some elements such that they line up with cells in the grid. For example, to edit the text in a cell I render a
<textarea />
absolutely positioned over the underlying cell. It needs to be perfectly aligned to preserve the illusion that you're directly editing the text in the cell. I also have to render some svg lines between nodes in the flowchart, etc. When scrolling the overlay items also need to stay positioned correctly relative to the cells.I'm currently achieving this (see link above) through a hack of getting a ref to FixedSizeGrid's
innerRef
and then usingReact.createPortal
to render the overlay elements into the same parent container as the cells. This gives the overlay items the same origin as the cells so they line up by default. This works, but of course is a hack and depends on some assumptions about the internals of react-window.My question is: Is there a more standard approach to this? I have seen discussions using ScrollSync, which I tried to implement without much success. There was too much lag / perf issues. I thought about modeling the overlay elements as grid items themselves but couldn't quite figure this out, especially for the
<svg>
element that renders the lines between nodes.Screenshots (or inspect element on knotend.com):
And the code looks roughly like this:
Thanks again!