Free Form Drag
#1180
Replies: 1 comment
-
This thread is old, but for posterity: You have to keep track of the draggable's new position yourself. The Storybook example uses an event handler for You'd need to create a reducer that takes advantage of Example for one draggable element: function MyComponent() {
const [position, setPosition] = useState<{x: number; y: number}>({ x: 0, y: 0 });
return <DndContext
onDragEnd={({ delta }) => {
setPosition(currentPosition => {
const newX = position.x + delta.x
const newY = position.y + delta.y
return { x: newX, y: newY }
}
}}
>
{/* Where draggable's position is controlled by prop `position` */}
<Draggable position={position} />
</DndContext> |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi All - I'm new to dnd-kit and am trying to make something draggable like this example in the docs - https://master--5fc05e08a4a65d0021ae0bf2.chromatic.com/?path=/story/core-draggable-hooks-usedraggable--snap-to-grid
I'm having a hard time getting the item to drop where it was dragged - does anyone have a working example?
Also, I was a bit unsure of whether we needed a droppable component - does simply dragging it around have to be enclosed within a droppable?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions