question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

monitor.getDifferenceFromInitialOffset reports wrong values in overflowing, autoscrolled container

See original GitHub issue

Some browsers (Chrome in my case, FF does not) allow you to drag elements to the edge of an overflowing container, and will scroll the container for you.

In this case monitor.getDifferenceFromInitialOffset() (and possiby others as well) will report wrong deltas because the scrolled distance is not being taken into account.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
filexandrcommented, Nov 18, 2019

Hello everybody,

I want back attention to the issue. We perform custom rendering of a drag item using custom DragLayer how it’s shown in https://react-dnd.github.io/react-dnd/examples/drag-around/custom-drag-layer. Everything works fine till the moment of dragging around edges of the container when auto scroll happens. I’ve forked original example and have created inner div with size 1000x1000 (styled with red border). Outer div is styled with overflow: ‘auto’. These are only 2 changes. You can try to drag to right or to bottom edge, wait till browser scrolling and drop the item somewhere. You should notice the item is disappeared and moved inside of original 300x300 box: https://codesandbox.io/s/react-dnd-example-6-eyw7w

This is because a drag item original coordinates are taken only on beginning of drag (INIT_COORDS action) and then during drag any shift of the item is not taken into account. So all monitor.get*Offset functions return wrong result. We performed custom compensation: when DragLayer renders we are taking getBoundingClientRect() for the drag item and add difference between original and current values to monitor offset. It works but sometimes the drag item is not compensated till a mouse move. So our thoughts on this, would be good to have :

  • this compensation built-in in the lib in effective, safe and performant way;
  • an example with relative custom DragLayer which moves together with container. In the case custom render of the drag item is stable on a scroll but still require compensation of coordinates on pointer move.

Hope somebody uses custom render with scroll and looking for the lib improvement in the area as we. Thanks and looking forward for a support!

Alex.

0reactions
gaearoncommented, Sep 17, 2015

Closing as inactive. Not sure this is actionable on library part.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to account for page scrolling with react-DND drop events?
It does not account for the additional movement from the auto scrolling. (e.g. if you pull it to the right of the screen...
Read more >
DragSourceMonitor - React DnD
The specific drag source bound to that monitor is called the monitor's owner below. Methods. canDrag() : Returns true if no drag operation...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found