I am trying to create a drag and drop feature that is a child component within a modal where the currently dragged item follows the position of the mouse, however, the position of the mouse is being offset by other content in the modal not part of the drag and drop component. Here is a repl showing the issue I would like for the element to follow the cursor exactly.
Showing the relation between cursor position and modal content
The basic element structure is as follows:
<Main>
<Modal>
<h2>Modal Header</h2>
<DndComponent>
<div>Drag Me</div>
<div>Element that follows cursor</div>
</DndComponent>
</Modal>
</Main>
I have tried different combinations of e.clientY, e.offsetY, and e.pageY in combination with getBoundingClientRect from the component container. I would prefer to not put a ref on the modal as the drag and drop feature will be used in many different places. I have also tried using both position: absolute and position: fixed