DnD how to differentiate elements when dragging them #3904
-
I want to change the bg-color of the drop target based on what iam dragging https://react-spectrum.adobe.com/react-aria/useDraggableCollection.html#droptarget In the above example when I drag but when i drag Basically I want something to tell me which element is being hovered over drop target Any help is much appreciated ! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You can share state of what's being dragged to the drop target. let [currentlyDragging, setCurrentlyDragging] = React.useState(null);
let onDragStart = (e) => {
setCurrentlyDragging(e.keys);
};
let onDragEnd = (e) => {
setCurrentlyDragging(null);
};
<Listbox
onDragStart={onDragStart}
onDragEnd={onDragEnd}
...
// Then pass currentlyDragging to your drop target
<DropTarget currentlyDragging={currentlyDragging} /> Example: https://codesandbox.io/s/dnd-custom-dropzone-cl9s01?file=/src/App.js |
Beta Was this translation helpful? Give feedback.
You can share state of what's being dragged to the drop target.
Example: https://codesandbox.io/s/dnd-custom-dropzone-cl9s01?file=/src/App.js