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 doesn't apply any unit conversion

See original GitHub issue

2. Describe the bug

Motion doesn’t convert non pixel units applied to elements before dragging begins. This means that something like this won’t work:

<motion.div
  initial={{ y: "100%" }}
  drag="y"
/>

Have a look at https://github.com/framer/motion/blob/master/src/behaviours/use-drag.ts#L373 In this case you’ll get origin[axis].get() returning "100%", and what should have been an arithmetic operation becomes a string concatenation ("100%3" for example).

I’m not entirely familiar with the source, but I have a feeling that somewhere around here: https://github.com/framer/motion/blob/master/src/behaviours/use-drag.ts#L436, where the origin motion values are initialised, there should also be a unit conversion.

I sort of hacked around this with an onDragStart handler and a gross oversimplification of unit-type-conversion.ts - https://codepen.io/angry-dan/pen/NWPwPQZ - which works for now, but I really think this should be dealt with by the library.

3. IMPORTANT: Provide a CodeSandbox reproduction of the bug https://codepen.io/angry-dan/pen/povdwvr

4. Steps to reproduce

Steps to reproduce the behavior:

  1. Go to https://codepen.io/angry-dan/pen/povdwvr
  2. Try to drag the element, note that you can’t
  3. Stop dragging, note the drag end transition converts the initial percentage to a px value and then further drags are possible.

5. Expected behavior Dragging even the first time should be possible.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
angry-dancommented, Aug 13, 2020

Whilst I still don’t have a workaround, this might be of interest - here I’m using the new layout prop to update an element’s position within a grid once dragging is done. Which does at least start to allow for “snap to grid” style dragging 👍

https://codesandbox.io/s/framer-motion-simple-animation-forked-7x8zy?file=/src/Example.tsx

0reactions
mmintelcommented, Mar 31, 2021

same issue with 4.0.3

Read more comments on GitHub >

github_iconTop Results From Across the Web

430548 – [Constraints] ConstraintLink not show on ... - Bugs - Eclipse
This doesn't work on the Luna nightly build from today. If i hide the constraint and the drag & drop it back onto...
Read more >
Button click event not fired when dragging mouse ... - Monorail
This seems to be causing some mouse clicks to not be triggered. The reason being is that the mouse is often moving when...
Read more >
Windows 11 Can't Drag And Drop Files To Taskbar, How To Fix
An obvious drawback of Windows 11 users have found is that it doesn't allow them to drag and drop files directly to the...
Read more >
can't upgrade materials/textures - Unity Forum
It doesn't say "Hidden/InternalError" it says: Default-Terrain-Standard material was not upgraded. There's no upgrader to convert Universal ...
Read more >
Known issues in After Effects - Adobe Support
Workaround: Try any of the following to make the render work: ... and drag with the Selection, Pen, Zoom, or other tools doesn't...
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