[BUG] Drag Controls not calculating correct position
See original GitHub issueBug 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:
- Created 3 years ago
- Reactions:2
- Comments:7
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.
In our case, we upgraded from
2.0.0-beta.77
to2.1.0
and started to notice:dragConstraints
property is not working properly for us any longerOn
2.0.0-beta.77
we are 100% confident, everything is working perfectly for us.framer-motion
for us with2.0.0-beta.77