The modern, lightweight, performant, accessible and extensible drag & drop toolkit for React.
Installations
npm install @thohui/dnd-kit-modifiers
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
21.6.1
NPM Version
10.2.4
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (93.03%)
CSS (6.32%)
JavaScript (0.47%)
HTML (0.18%)
validate.email 🚀
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Developer
Download Statistics
Total Downloads
21
Last Day
1
Last Week
1
Last Month
1
Last Year
21
GitHub Statistics
MIT License
2 Stars
472 Commits
1 Forks
2 Branches
1 Contributors
Updated on Mar 01, 2024
Bundle Size
2.22 kB
Minified
977.00 B
Minified + Gzipped
Package Meta Information
Latest Version
10.1.0
Package Id
@thohui/dnd-kit-modifiers@10.1.0
Unpacked Size
48.13 kB
Size
10.71 kB
File Count
21
NPM Version
10.2.4
Node Version
21.6.1
Published on
Feb 17, 2024
Total Downloads
Cumulative downloads
Total Downloads
21
Last Day
0%
1
Compared to previous day
Last Week
0%
1
Compared to previous week
Last Month
-50%
1
Compared to previous month
Last Year
0%
21
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
2
Peer Dependencies
2
Dev Dependencies
1
@dnd-kit/modifiers
Modifiers let you dynamically modify the movement coordinates that are detected by sensors. They can be used for a wide range of use cases, for example:
- Restricting motion to a single axis
- Restricting motion to the draggable node container's bounding rectangle
- Restricting motion to the draggable node's scroll container bounding rectangle
- Applying resistance or clamping the motion
Installation
To start using modifiers, install the modifiers package via yarn or npm:
npm install @dnd-kit/modifiers
Usage
The modifiers repository contains a number of useful modifiers that can be applied on DndContext
as well as DragOverlay
.
1import {DndContext, DragOverlay} from '@dnd-kit'; 2import { 3 restrictToVerticalAxis, 4 restrictToWindowEdges, 5} from '@dnd-kit/modifiers'; 6 7function App() { 8 return ( 9 <DndContext modifiers={[restrictToVerticalAxis]}> 10 {/* ... */} 11 <DragOverlay modifiers={[restrictToWindowEdges]}>{/* ... */}</DragOverlay> 12 </DndContext> 13 ); 14}
As you can see from the example above, DndContext
and DragOverlay
can both have different modifiers.
Built-in modifiers
Restricting motion to an axis
restrictToHorizontalAxis
Restrict movement to only the horizontal axis.
restrictToVerticalAxis
Restrict movement to only the vertical axis.
Restrict motion to a container's bounding rectangle
restrictToWindowEdges
Restrict movement to the edges of the window. This modifier can be useful to prevent the DragOverlay
from being moved outside of the bounds of the window.
restrictToParentElement
Restrict movement to the parent element of the draggable item that is picked up.
restrictToFirstScrollableAncestor
Restrict movement to the first scrollable ancestor of the draggable item that is picked up.
Snap to grid
createSnapModifier
Function to create modifiers to snap to a given grid size.
1import {createSnapModifier} from '@dnd-kit/modifiers'; 2 3const gridSize = 20; // pixels 4const snapToGridModifier = createSnapModifier(gridSize);
Snap to cursor
snapCenterToCursor
Snaps the center of the draggable item to the cursor when it is picked up. Has no effect when using the Keyboard sensor.
Building custom modifiers
To build your own custom modifiers, refer to the implementation of the built-in modifiers of this package.
For example, here is an implementation to create a modifier to snap to grid:
1const gridSize = 20; 2 3function snapToGrid(args) { 4 const {transform} = args; 5 6 return { 7 ...transform, 8 x: Math.ceil(transform.x / gridSize) * gridSize, 9 y: Math.ceil(transform.y / gridSize) * gridSize, 10 }; 11}

No vulnerabilities found.

No security vulnerabilities found.