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.

[BUG] Drag Controls not calculating correct position

See original GitHub issue

Bug Behavior

After upgrading to 2.1.0 from 1.x, the drag controls do not position the element correctly.

Example Code

Below is example of the code:

const variants = {
  active: {
    opacity: 1,
    scale: 1
  },
  inactive: {
    opacity: 0,
    scale: 0.5
  }
};

const Drag = () => {
  const dragControls = useDragControls();
  const [activeDrag, setActiveDrag] = useState<any | null>(null);

  const onDragStart = useCallback(
    (event, data) => {
      setActiveDrag(data);
      dragControls.start(event, { snapToCursor: true });
    },
    [dragControls]
  );

  const onDragEnd = useCallback(() => {
    setActiveDrag(null);
  }, [activeDrag]);

  return (
    <div>
      <button onDragStart={onDragStart} onDragEnd={onDragEnd}>Drag me</button>
      <motion.div
        drag
        dragControls={dragControls}
        variants={variants}
        animate={activeDrag ? 'active' : 'inactive'}
        onDragEnd={onDragEnd}
      >
        {activeDrag && (
          <div>
            <img
              height="50"
              width="50"
              alt="logo"
              src={img}
            />
          </div>
        )}
      </motion.div>
    </div>
  );
};

Video

https://www.screencast.com/t/P5vEKY9TK

Environment details

Mac, Chrome

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:7

github_iconTop GitHub Comments

6reactions
mattgperrycommented, Jul 24, 2020

@o-alexandrov Hopefully this PR fixes your issue https://github.com/framer/motion/pull/660 when it lands. Please open a ticket with a sandbox if it doesn’t though.

3reactions
o-alexandrovcommented, Jul 20, 2020

In our case, we upgraded from 2.0.0-beta.77 to 2.1.0 and started to notice:

  • dragConstraints property is not working properly for us any longer

On 2.0.0-beta.77 we are 100% confident, everything is working perfectly for us.

  • we downgraded, redeployed, and everything is fine with framer-motion for us with 2.0.0-beta.77
Read more comments on GitHub >

github_iconTop Results From Across the Web

27977 – drag drop threshold region not calculated ... - Bugs - Eclipse
This bug can be observed with any control marked as a drag source, so long as the control is not located at (0,...
Read more >
Draggable HTML elements positioning BUG - Stack Overflow
There seems to be a basic problem that the dragger elements are all given position relative. I think they need to be absolute...
Read more >
Fix problem: Drag and drop not working in Windows
Drag and drop is no longer working in Windows 10 or Windows 11? Here's how to fix this problem in just a couple...
Read more >
[Draggable] Bug while dragging inside rotated element (with ...
Hi, I would like to report a bug found using Draggable (great library!), hope this is the right place.If you drag an element...
Read more >
Drag'n'Drop with mouse events - The Modern JavaScript Tutorial
Correct positioning · When a visitor presses the button ( mousedown ) – remember the distance from the pointer to the left-upper corner...
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