react-grid-layout / react-grid-layout/react-draggable
Draggable does not work as intended in 4.4.6. (Normal operation in 4.4.5)
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 9.3k
- Forks
- 1k
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 4
Description
In version 4.4.6, the mouse leaves the draggable component.
When not to use state
import { useRef } from "react";
import Draggable from "react-draggable";
import "./App.css";
function App() {
const nodeRef = useRef<HTMLDivElement>(null);
return (
<Draggable handle={`.handler`} nodeRef={nodeRef}>
<div ref={nodeRef} style={{ width: "500px" }}>
<div className="handler" style={{ backgroundColor: "gray" }}>
React Draggable 4.4.6
</div>
<div>Body</div>
</div>
</Draggable>
);
}
export default App;
When to use states
import { useCallback, useRef, useState } from "react";
import Draggable, { DraggableData, DraggableEvent } from "react-draggable";
import "./App.css";
function App() {
const nodeRef = useRef<HTMLDivElement>(null);
const [position, setPosition] = useState({ x: 0, y: 0 });
const handleDrag = useCallback((e: DraggableEvent, data: DraggableData) => {
setPosition({ x: data.x, y: data.y });
console.log(data);
}, []);
return (
<Draggable
handle={`.handler`}
nodeRef={nodeRef}
position={position}
onDrag={handleDrag}
>
<div ref={nodeRef} style={{ width: "500px" }}>
<div className="handler" style={{ backgroundColor: "gray" }}>
React Draggable 4.4.6
</div>
<div>Body</div>
</div>
</Draggable>
);
}
export default App;
4.4.6 with console log
https://github.com/react-grid-layout/react-draggable/assets/59780565/a41c47d3-7793-4c68-bae1-f043297eaa22
4.4.5 with console log
https://github.com/react-grid-layout/react-draggable/assets/59780565/04ce9bb2-1aab-43a8-84ff-aea73a704178
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the supplied App component with the Draggable entry point, comparing 4.4.6 against 4.4.5; the examples use App.css and both uncontrolled and state-controlled cases. Trace the handle and nodeRef behavior, then verify that dragging remains effective and that the state example still logs and updates position.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100