apps/docs/solid/components/drag-overlay.mdx
The DragOverlay component renders a custom overlay element while a drag operation is in progress. This allows you to display a completely different element than the one being dragged, which is useful for rendering a styled clone, a preview, or a simplified representation of the dragged element.
Import and place the DragOverlay component inside a DragDropProvider. Its children will only be rendered when a drag operation is active.
import {DragDropProvider, DragOverlay, useDraggable} from '@dnd-kit/solid';
function Draggable() {
const {ref} = useDraggable({id: 'draggable'});
return (
<>
<button ref={ref}>Draggable</button>
<DragOverlay>
<div>I will be rendered while dragging...</div>
</DragOverlay>
</>
);
}
You can pass a function as a child to the DragOverlay component, which will receive the source as an argument. This is useful for rendering different content depending on which element is being dragged.
import {DragDropProvider, DragOverlay} from '@dnd-kit/solid';
function App() {
return (
<DragDropProvider>
<Draggable id="foo" />
<Draggable id="bar" />
<DragOverlay>
{source => (
<div>Dragging {source.id}</div>
)}
</DragOverlay>
</DragDropProvider>
);
}
By default, when a drag operation ends, the overlay animates back to the position of the source element. You can customize or disable this animation using the dropAnimation prop.
<DragOverlay dropAnimation={null}>
<div>No animation on drop</div>
</DragOverlay>
<DragOverlay dropAnimation={{ duration: 150, easing: 'ease-out' }}>
<div>Fast drop animation</div>
</DragOverlay>
undefined – use the default animation (250ms ease)null – disable the drop animation entirely{duration, easing} – customize the animation timing(context) => Promise<void> | void – provide a fully custom animation function
</ParamField>