Skip to main content

Overview

Modifiers transform the movement of draggable elements during drag operations. They can restrict movement to axes or boundaries, adjust positioning, or implement any custom movement logic.

Built-in Modifiers

Abstract Modifiers

Available in @dnd-kit/abstract/modifiers, these modifiers are environment-agnostic:

RestrictToHorizontalAxis

Constrain movement to the horizontal axis only

RestrictToVerticalAxis

Constrain movement to the vertical axis only

SnapModifier

Snap movement to a grid with configurable size
Example using axis restriction:
Example combining modifiers:
Modifiers are applied in order, so place restrictions before transformations.

Concrete Modifiers

Environment-specific modifiers for the DOM, available in @dnd-kit/dom/modifiers:

RestrictToWindow

Constrain movement within the window boundaries

RestrictToElement

Constrain movement within a container element

Usage

Modifiers can be applied globally or per draggable element. The modifiers option accepts either an array or a function that receives the default modifiers.

Extending defaults

Use the function form to add modifiers without replacing the defaults:

Replacing defaults

Pass an array to fully replace the default modifiers:

Per-draggable modifiers

Modifiers can also be configured on individual draggable elements:
Local modifiers on draggable elements take precedence over global modifiers.

Creating Custom Modifiers

Create custom modifiers by extending the Modifier class:

Modifier Lifecycle

  1. Construction
    • Modifier instance created
    • Options configured
  2. Application
    • apply() called during drag
    • Transforms coordinates
    • Can access drag operation state
  3. Cleanup
    • Resources cleaned up on destroy

API Reference

Base Modifier Class

DragDropManager
required
Reference to the drag and drop manager instance.
Record<string, any>
Optional configuration for the modifier.

Methods

  • apply(operation): Transform drag coordinates
  • enable(): Enable the modifier
  • disable(): Disable the modifier
  • isDisabled(): Check if modifier is disabled
  • destroy(): Clean up resources

Static Methods

  • configure(options): Create configured modifier