Overview
Plugins:- Extend drag and drop behavior without modifying core code
- React to drag operation changes through effects
- Can be configured globally or per-draggable
- Support options for customization
- Can be enabled/disabled dynamically
- Follow a consistent lifecycle
Plugin base class
All plugins extend thePlugin base class:
Built-in plugins
The@dnd-kit/dom package includes several useful plugins:
Feedback
Provides visual feedback during drag operations:- Creates a visual representation of the dragged element
- Follows the pointer during drag
- Supports custom rendering
- Handles animations and transitions
Accessibility
Provides screen reader announcements:- When a drag starts
- When hovering over a droppable
- When a drag ends (dropped or canceled)
AutoScroller
Automatically scrolls containers when dragging near edges:Cursor
Manages cursor styles during drag:grabbingwhile dragginggrabon hovernot-allowedwhen can’t drop
PreventSelection
Prevents text selection during drag:Core plugins
Some plugins are required for core functionality:CollisionNotifier
Updates the drag target based on collision detection:ScrollListener & Scroller
These DOM-specific plugins track and manage scroll offsets:Creating custom plugins
Extend thePlugin class to create custom functionality:
Basic example
With options
Analytics plugin
Visual feedback plugin
Plugin lifecycle
Construction
Plugins are instantiated when registered with the manager:Effects
UseregisterEffect to react to drag operation changes:
Destruction
Plugins are destroyed when the manager is destroyed:Configuration
Global plugins
Apply to all drag operations:Per-draggable plugins
Apply to specific draggables:Plugin descriptors
Theconfigure method returns a descriptor:
Enable/disable plugins
Plugins can be enabled or disabled at runtime:- Still exist in the registry
- Effects still run
- Should check
isDisabled()and skip their logic
Accessing plugins
Get registered plugins from the manager:Plugin registry
The manager maintains a plugin registry:Per-draggable plugin configuration
Draggables can look up their plugin configuration:Type safety
Plugins can be typed with their manager type:Best practices
Support options: Make your plugins configurable with options. Use the
configure pattern for user-friendly configuration.Example: Undo/Redo plugin
Related
Custom plugins
Build your own plugins
Modifiers
Transform coordinates
Plugins API
Plugin API reference
DOM plugins
Built-in DOM plugins