Gathering detailed insights and metrics for @dnd-kit/utilities
Gathering detailed insights and metrics for @dnd-kit/utilities
Gathering detailed insights and metrics for @dnd-kit/utilities
Gathering detailed insights and metrics for @dnd-kit/utilities
@dnd-kit/core
dnd kit – a lightweight React library for building performant and accessible drag and drop experiences
@dnd-kit/accessibility
A generic toolkit to help with accessibility
@dnd-kit/sortable
Official sortable preset and sensors for dnd kit
@dnd-kit/modifiers
Translate modifier presets for use with `@dnd-kit` packages.
The modern, lightweight, performant, accessible and extensible drag & drop toolkit for React.
npm install @dnd-kit/utilities
96.6
Supply Chain
67.1
Quality
75.9
Maintenance
100
Vulnerability
100
License
@dnd-kit/sortable@9.0.0
Published on 23 Nov 2024
@dnd-kit/core@6.2.0
Published on 23 Nov 2024
@dnd-kit/modifiers@8.0.0
Published on 23 Nov 2024
@dnd-kit/accessibility@3.1.1
Published on 23 Nov 2024
@dnd-kit/helpers@0.0.5
Published on 11 Jul 2024
@dnd-kit/collision@0.0.5
Published on 11 Jul 2024
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
13,251 Stars
471 Commits
656 Forks
37 Watching
28 Branches
49 Contributors
Updated on 28 Nov 2024
Minified
Minified + Gzipped
TypeScript (92.59%)
CSS (6.73%)
JavaScript (0.49%)
HTML (0.19%)
Cumulative downloads
Total Downloads
Last day
-8.3%
371,446
Compared to previous day
Last week
4.6%
2,105,484
Compared to previous week
Last month
12.4%
8,673,503
Compared to previous month
Last year
133.2%
80,519,380
Compared to previous year
useDraggable
and useDroppable
. and won't force you to re-architect your app or create additional wrapper DOM nodes.@dnd-kit/sortable
, which is a thin layer built on top of @dnd-kit/core
. More presets coming in the future.To learn how to get started with dnd kit, visit the official documentation website. You'll find in-depth API documentation, tips and guides to help you build drag and drop interfaces.
The core library of dnd kit exposes two main concepts:
Augment your existing components using the useDraggable
and useDroppable
hooks, or combine both to create components that can both be dragged and dropped over.
Handle events and customize the behaviour of your draggable elements and droppable areas using the <DndContext>
provider. Configure sensors to handle different input methods.
Use the <DragOverlay>
component to render a draggable overlay that is removed from the normal document flow and is positioned relative to the viewport.
Check out our quick start guide to learn how get started.
Extensibility is at the core of dnd kit. It is built to be lean and extensible. It ships with the features we believe most people will want most of the time, and provides extension points to build the rest on top of @dnd-kit/core
.
A prime example of the level of extensibility of dnd kit is the Sortable preset, which is built using the extension points that are exposed by @dnd-kit/core
.
The primary extension points of dnd kit are:
Building accessible drag and drop interfaces is hard; dnd kit has a number of sensible defaults and starting points to help you make your drag and drop interface accessible:
aria
attributes that should be passed to draggable itemsCheck out our Accessibility guide to learn more about how you can help provide a better experience for screen readers.
Unlike most drag and drop libraries, dnd kit intentionally is not built on top of the HTML5 Drag and drop API. This was a deliberate architectural decision, that does come with tradeoffs that you should be aware of before deciding to use it, but for most applications, we believe the benefits outweigh the tradeoffs.
The HTML5 Drag and drop API has some severe limitations. It does not support touch devices or using the keyboard to drag items, which means that the libraries that are built on top of it need to expose an entirely different implementation to support those input methods. It also doesn't support common use-cases such as locking dragging to a specific axis or to the bounds of a container, custom collision detection strategies, or even customizing the preview of the dragged item.
While there are workarounds to some of these issues, those workarounds typically increase the complexity of the codebase and the overall bundle size of the library, and lead to inconsistencies between the mouse, touch and keyboard layers because they're powered by entirely different implementations.
The main tradeoff with not using the HTML5 Drag and drop API is that you won't be able to drag from the desktop or between windows. If the drag and drop use-case you have in mind involves this kind of functionality, you'll definitely want to use a library that's built on top of the HTML 5 Drag and drop API. We highly recommend you check out react-dnd for a React library that's has a native HTML 5 Drag and drop backend.
dnd kit lets you build drag and drop interfaces without having to mutate the DOM every time an item needs to shift position.
This is possible because dnd kit lazily calculates and stores the initial positions and layout of your droppable containers when a drag operation is initiated. These positions are passed down to your components that use useDraggable
and useDroppable
so that you can compute the new positions of your items while a drag operation is underway, and move them to their new positions using performant CSS properties that do not trigger a repaint such as translate3d
and scale
. For an example of how this can be achieved, check out the implementation of the sorting strategies that are exposed by the @dnd-kit/sortable
library.
This isn't to say that you can't shift the position of the items in the DOM while dragging, this is something that is supported and sometimes inevitable. In some cases, it won't be possible to know in advance what the new position and layout of the item until you move it in the DOM. Just know that these kind of mutations to the DOM while dragging are much more expensive and will cause a repaint, so if possible, prefer computing the new positions using translate3d
and scale
.
dnd kit also uses SyntheticEvent listeners for the activator events of all sensors, which leads to improved performance over manually adding event listeners to each individual draggable node.
@dnd-kit
repository@dnd-kit/core
@dnd-kit/accessibility
@dnd-kit/sortable
@dnd-kit/modifiers
@dnd-kit/utilities
You'll need to install all the dependencies in the root directory. Since the @dnd-kit
is a monorepo that uses Lerna and Yarn Workspaces, npm CLI is not supported (only yarn).
1yarn install
This will install all dependencies in each project, build them, and symlink them via Lerna
In one terminal, run yarn start
in parallel:
1yarn start
This builds each package to <packages>/<package>/dist
and runs the project in watch mode so any edits you save inside <packages>/<package>/src
cause a rebuild to <packages>/<package>/dist
. The results will stream to to the terminal.
1yarn start:storybook
Runs the storybook Open http://localhost:6006 to view it in the browser.
You can play with local packages in the Parcel-powered playground.
1yarn start:playground
This will start the playground on localhost:1234
. If you have lerna running watch in parallel mode in one terminal, and then you run parcel, your playground will hot reload when you make changes to any imported module whose source is inside of packages/*/src/*
. Note that to accomplish this, each package's start
command passes TDSX the --noClean
flag. This prevents Parcel from exploding between rebuilds because of File Not Found errors.
Important Safety Tip: When adding/altering packages in the playground, use alias
object in package.json. This will tell Parcel to resolve them to the filesystem instead of trying to install the package from NPM. It also fixes duplicate React errors you may run into.
(In a third terminal) you can run Cypress and it will run the integration tests against storybook.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
21 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 10
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 7/14 approved changesets -- score normalized to 5
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
80 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More