Custom Animations
The Feedback plugin in dnd-kit provides powerful animation capabilities through drop animations, transitions, and visual feedback customization. This guide shows you how to create custom animations for polished drag and drop experiences.Understanding the Feedback Plugin
The Feedback plugin manages the visual representation of draggable items during and after drag operations. It handles:- Drag feedback rendering (default, move, clone, or none)
- Drop animations when items are released
- Keyboard transition smoothing
- Transform and positioning calculations
Drop Animations
Drop animations control what happens when a draggable item is released.Built-in Drop Animation
The default drop animation smoothly returns items to their final position:packages/dom/src/core/plugins/feedback/Feedback.ts
Disabling Drop Animation
SetdropAnimation to null to disable it entirely:
Per-Item Drop Animation
Override drop animation settings for individual draggables:Custom Drop Animation Function
Create completely custom drop animations:Keyboard Transitions
When dragging with keyboard controls, smooth transitions make the experience feel more natural:packages/dom/src/core/plugins/feedback/Feedback.ts
Feedback Types
The Feedback plugin supports different visual feedback modes:Default Feedback
The draggable element moves with the cursor:Move Feedback
The actual element moves without a placeholder:Clone Feedback
Creates a visual clone while keeping the original in place:No Feedback
Disables visual feedback entirely:Advanced Animation Examples
Example 1: Bounce Drop Animation
Create a playful bounce effect when items are dropped:Example 2: Fade and Shrink Animation
Example 3: Success/Error Animation
Animate differently based on whether the drop was successful:Example 4: Morphing Animation
Smoothly morph the dragged element into its final position and size:Custom Root Element
Control where feedback elements are rendered:packages/dom/src/core/plugins/feedback/Feedback.ts
Respecting Reduced Motion
The Feedback plugin automatically respects the user’s reduced motion preferences. Whenprefers-reduced-motion is enabled, keyboard transitions are automatically disabled.
You can also check this preference in custom animations:
Tips for Great Animations
- Keep animations short: 200-400ms is usually ideal for drag and drop interactions.
-
Use appropriate easing:
cubic-bezier(0.25, 1, 0.5, 1)provides natural-feeling motion. - Always call cleanup and restoreFocus: These are essential for proper state management.
- Test with keyboard navigation: Ensure animations work well with keyboard controls.
-
Consider performance: Use
transformandopacityfor best performance, as they can be hardware-accelerated. -
Respect user preferences: Always honor
prefers-reduced-motionsettings.