Extensibility
Plugins
Extend beyond the core functionality with plugins.
Overview
Plugins are a powerful way to extend the core functionality of @dnd-kit. They can be used to add new features, modify existing behavior, or react to drag and drop operations.
Built-in Plugins
Several plugins are included by default:
Accessibility
: Manages ARIA attributes for drag and drop operationsAutoScroller
: Automatically scrolls containers when dragging near edgesCursor
: Updates cursor styles during drag operationsFeedback
: Manages visual feedback during draggingPreventSelection
: Prevents text selection while draggingScrollListener
: Tracks scroll events during drag operationsScroller
: Handles programmatic scrolling
Creating a Plugin
To create a custom plugin, extend the Plugin
class:
Using Plugins
Plugins can be added when creating a DragDropManager:
Plugin Lifecycle
- Construction: Plugin instance created with manager reference
- Configuration: Options applied if provided
- Registration: Plugin registered with manager
- Operation: Plugin effects are run
- Cleanup: Plugin destroyed when manager is destroyed
API Reference
Plugin Class
The base class for all plugins:
Reference to the drag and drop manager instance.
Optional configuration options for the plugin.
Properties
disabled
: Whether the plugin is currently disabledoptions
: Current plugin options
Methods
enable()
: Enable the plugindisable()
: Disable the pluginisDisabled()
: Check if plugin is disabledconfigure(options)
: Update plugin optionsdestroy()
: Clean up plugin resourcesregisterEffect(callback)
: Register a reactive effect
Static Methods
configure(options)
: Create a configured plugin descriptor
Plugin Options
Options passed to plugins should be plain objects:
Effects
Plugins can register effects that automatically clean up:
Best Practices
- Clean Up Resources: Always clean up listeners and timers in the
destroy
method - Check Disabled State: Check
this.disabled
before performing operations - Use Type Safety: Leverage TypeScript for better type checking
- Document Options: Clearly document all available options
- Follow Patterns: Study built-in plugins for patterns and conventions