Overview
Modifiers transform the movement of draggable elements during drag operations. They can restrict movement to axes or boundaries, adjust positioning, or implement custom movement logic. This guide covers how to use modifiers in React with hooks likeuseDraggable and useSortable.
Restricting to a container element
Use theRestrictToElement modifier from @dnd-kit/dom/modifiers to constrain dragging within a container. Pass the container’s DOM element via a React ref:
Restricting to the window
UseRestrictToWindow from @dnd-kit/dom/modifiers to prevent dragging outside the browser viewport:
Restricting to an axis
UseRestrictToVerticalAxis or RestrictToHorizontalAxis from @dnd-kit/abstract/modifiers to lock movement to a single axis:
Snapping to a grid
Use theSnapModifier from @dnd-kit/abstract/modifiers to snap movement to a grid:
size option accepts a number for uniform snapping, or an object with separate x and y values:
Combining modifiers
You can combine multiple modifiers. They are applied in order:Global vs. per-draggable modifiers
Modifiers can be set globally on theDragDropProvider to apply to all draggable elements, or on individual hooks for per-element control.
Global modifiers
Per-draggable modifiers
Per-draggable modifiers take precedence over global modifiers:For the full list of built-in modifiers and how to create custom modifiers, see the core Modifiers documentation.