NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
npm · #2061 most downloaded on npm
dnd kit – a lightweight React library for building performant and accessible drag and drop experiences
Last release 2 years ago
no release in 18 months
Ships unpredictably
gaps range from 9 days to 13 months
Nearly every release is documented
notes for 41 of 41 stable releases
Nothing withdrawn
no release was ever pulled
6 years old
140 releases · first in 2021
One column per quarter.
### Patch Changes - #1534 `93602df` Thanks @duvallj! - Workaround layout bug by adding explicit top and left attributes. Under sufficiently complex CS
dbe0087 #335 Thanks @clauderic! - Fix getEventListenerTarget when target element is not an instance of HTMLElement
5d4d292 #331 Thanks @phungleson! - Fix typo in SensorContext type (scrollAdjustedTransalte --> scrollAdjustedTranslate)
`d39ab11` #316 Thanks @lsit! - Added ability to optionally return screen reader announcements onDragMove.
`ae398de` Thanks @clauderic! - Allow setting an optional id prop on DndContext to fix a warning during server-side rendering (especially in Next.js).
ae398de Thanks @clauderic! - Allow setting an optional id prop on DndContext to fix a warning during server-side rendering (especially in Next.js). By default, this id is autogenerated and can lead to a mismatch between the server- and client-side rendered HTML. We also avoid this mismatch by rendering the Accessibility component only after everything else was initially mounted on the client.
8b938ce Thanks @clauderic! - Hide the node in the overlay after the drop animation is finished. This prevents some flickering with React concurrent mode.
`0ff788e` #246 Thanks @inokawa! - DragOverlay component now passes down style prop to the wrapper element it renders.
`54c8778` #225 Thanks @clauderic! - Updated the active rects type to ViewRect (was previously incorrectly typed as LayoutRect)
`f9ec28f` #217 Thanks @clauderic! - Fixes a regression introduced with @dnd-kit/core@3.0.0 that was causeing sensors to stop working after a drag oper
f9ec28f #217 Thanks @clauderic! - Fixes a regression introduced with @dnd-kit/core@3.0.0 that was causeing sensors to stop working after a drag operation where activation constraints were not met.`a9d92cf` #174 Thanks @clauderic! - Distributed assets now only target modern browsers. Browserlist config:
a9d92cf #174 Thanks @clauderic! - Distributed assets now only target modern browsers. Browserlist config:
defaults
last 2 version
not IE 11
not dead
If you need to support older browsers, include the appropriate polyfills in your project's build process.
b406cb9 #187 Thanks @clauderic! - Introduced the useDndMonitor hook. The useDndMonitor hook can be used within components wrapped in a DndContext provider to monitor the different drag and drop events that happen for that DndContext.
Example usage:
import {DndContext, useDndMonitor} from '@dnd-kit/core';
function App() {
return (
<DndContext>
<Component />
</DndContext>
);
}
function Component() {
useDndMonitor({
onDragStart(event) {},
onDragMove(event) {},
onDragOver(event) {},
onDragEnd(event) {},
onDragCancel(event) {},
});
}
b7355d1 #207 Thanks @clauderic! - The data argument for useDraggable and useDroppable is now exposed in event handlers and on the active and over objects.
Example usage:
import {DndContext, useDraggable, useDroppable} from '@dnd-kit/core';
function Draggable() {
const {attributes, listeners, setNodeRef, transform} = useDraggable({
id: 'draggable',
data: {
type: 'type1',
},
});
/* ... */
}
function Droppable() {
const {setNodeRef} = useDroppable({
id: 'droppable',
data: {
accepts: ['type1', 'type2'],
},
});
/* ... */
}
function App() {
return (
<DndContext
onDragEnd={({active, over}) => {
if (over?.data.current.accepts.includes(active.data.current.type)) {
// do stuff
}
}}
/>
);
}
`2833337` #186 Thanks @clauderic! - Simplify useAnnouncement hook to only return a single announcement rather than entries. Similarly, the LiveRegion
2833337 #186 Thanks @clauderic! - Simplify useAnnouncement hook to only return a single announcement rather than entries. Similarly, the LiveRegion component now only accepts a single announcement rather than `entries.
Updated dependencies [c24bdb3, 2833337]:
`cc0a6ff` #177 Thanks @FinestV! - fix calculations for top and left auto scroll speed
`bdb1aa2` #171 Thanks @mitchheddles! - Added more flexibility for the distance and tolerance activation constraints. Consumers can still provide a num
bdb1aa2 #171 Thanks @mitchheddles! - Added more flexibility for the distance and tolerance activation constraints. Consumers can still provide a number to calculate the distance or tolerance constraints, but can now also pass in an object that adheres to the DistanceMeasurement interface instead. This change allows consumers to specify which axis the activation distance or tolerance should be measured against, either x, y or both.
type DistanceMeasurement =
| number
| {x: number}
| {y: number}
| {x: number, y: number}
interface DistanceConstraint {
distance: DistanceMeasurement;
}
interface DelayConstraint {
delay: number;
tolerance: DistanceMeasurement;
}
Example usage:
For example, when building a list that can only be sorted vertically when using the restrictToVerticalAxis modifier, a consumer can now configure sensors to only measure distance against the y axis when using the MouseSensor, and afford more tolerance on the y axis than the x axis for the TouchSensor:
const sensors = useSensors(
useSensor(MouseSensor, {
activationConstraint: {
distance: { y: 10 },
},
}),
useSensor(TouchSensor, {
activationConstraint: {
delay: 250,
tolerance: { y: 15, x: 5 },
},
}),
);
This also fixes a bug with the way the distance is calculated when passing a number to the distance or tolerance options. Previously, the sum of the distance on both the x and y axis was being calculated rather than the hypothenuse.
`f038174` #166 Thanks @shayc! - AutoScrollActivator enum was being exported as a type rather than a value.
`a847a80` #160 Thanks @clauderic! - Allow consumers to define drag source opacity in drop animation by setting the dragSourceOpacity option to a numbe
a847a80 #160 Thanks @clauderic! - Allow consumers to define drag source opacity in drop animation by setting the dragSourceOpacity option to a number on the dropAnimation prop of DragOverlay.
ea9d878 #164 Thanks @clauderic! - Export AutoScrollActivator enum for consumers.
`8583825` #140 Thanks @clauderic! - Auto-scrolling defaults have been updated, which should generally lead to improved user experience for most consum
8583825 #140 Thanks @clauderic! - Auto-scrolling defaults have been updated, which should generally lead to improved user experience for most consumers.
The auto-scroller now bases its calculations based on the position of the pointer rather than the edges of the draggable element's rect by default. This change is aligned with how the native HTML 5 Drag & Drop auto-scrolling behaves.
This behaviour can be customized using the activator option of the autoScroll prop:
import {AutoScrollActivator, DndContext} from '@dnd-kit/core';
<DndContext autoScroll={{activator: AutoScrollActivator.DraggableRect}} />;
The auto-scroller now also looks at scrollable ancestors in order of appearance in the DOM tree, meaning it will first attempt to scroll the window, and narrow its focus down rather than the old behaviour of looking at scrollable ancestors in order of closeness to the draggable element in the DOM tree (reversed tree order).
This generally leads to an improved user experience, but can be customized by passing a configuration object to the autoScroll prop that sets the order option to TraversalOrder.ReversedTreeOrder instead of the new default value of TraversalOrder.TreeOrder:
import {DndContext, TraversalOrder} from '@dnd-kit/core';
<DndContext autoScroll={{order: TraversalOrder.ReversedTreeOrder}} />;
The autoscrolling thresholds, acceleration and interval can now also be customized using the autoScroll prop:
import {DndContext} from '@dnd-kit/core';
<DndContext
autoScroll={{
thresholds: {
// Left and right 10% of the scroll container activate scrolling
x: 0.1,
// Top and bottom 25% of the scroll container activate scrolling
y: 0.25,
},
// Accelerate slower than the default value (10)
acceleration: 5,
// Auto-scroll every 10ms instead of the default value of 5ms
interval: 10,
}}
/>;
Finally, consumers can now conditionally opt out of scrolling certain scrollable ancestors using the canScroll option of the autoScroll prop:
import {DndContext} from '@dnd-kit/core';
<DndContext
autoScroll={{
canScroll(element) {
if (element === document.scrollingElement) {
return false;
}
return true;
},
}}
/>;
`79f6088` #144 Thanks @clauderic! - Allow consumers to determine whether to animate layout changes and when to measure nodes. Consumers can now use th
79f6088 #144 Thanks @clauderic! - Allow consumers to determine whether to animate layout changes and when to measure nodes. Consumers can now use the animateLayoutChanges prop of useSortable to determine whether layout animations should occur. Consumers can now also decide when to measure layouts, and at what frequency using the layoutMeasuring prop of DndContext. By default, DndContext will measure layouts just-in-time after sorting has begun. Consumers can override this behaviour to either only measure before dragging begins (on mount and after dragging), or always (on mount, before dragging, after dragging). Pairing the layoutMeasuring prop on DndContext and the animateLayoutChanges prop of useSortable opens up a number of new possibilities for consumers, such as animating insertion and removal of items in a sortable list.
a76cd5a #136 Thanks @clauderic! - Added onActivation option to sensors. Delegated the responsibility of calling event.preventDefault() on activation to consumers, as consumers have the most context to decide whether it is appropriate or not to prevent the default browser behaviour on activation. Consumers of the sensors can prevent the default behaviour on activation using the onActivation option. Here is an example using the Pointer sensor: useSensor(PointerSensor, {onActivation: (event) => event.preventDefault()})
adb7bd5 #151 Thanks @clauderic! - DragOverlay now attempts to perform drop animation even if transform.x and transform.y are both zero.`ac674e8` #135 Thanks @ranbena! - Added dragCancel prop to DndContext. The dragCancel prop can be used to cancel a drag operation on drop. The prop ac
ac674e8 #135 Thanks @ranbena! - Added dragCancel prop to DndContext. The dragCancel prop can be used to cancel a drag operation on drop. The prop accepts a function that returns a boolean, or a promise returning a boolean once resolved. Return false to cancel the drop.
208f68e #111 Thanks @ranbena! - Keyboard sensor now cancels dragging on window resize
`423610c` #56 Thanks @clauderic! - Add MIT license to package.json and distributed files
423610c #56 Thanks @clauderic! - Add MIT license to package.json and distributed files
594a24e #106 Thanks @ranbena! - Replace animation.finished with animation.onfinish for DragOverlay drop animation as the latter has much better support across browsers.
fd25eaf #68 Thanks @Pustelto! - Wrap attributes returned from useDraggable hook in useMemo to allow pure component optimization
Updated dependencies [423610c]:
`5194696` #51 Thanks @clauderic! - Fix issue with reducer initial state variable causing collisions due to variable references all pointing to the ori
5194696 #51 Thanks @clauderic! - Fix issue with reducer initial state variable causing collisions due to variable references all pointing to the original initial state variable.
310bbd6 #37 Thanks @nickpresta! - Fix typo in package.json repository URL
Updated dependencies [0b343c7, 310bbd6]:
`2912350` Thanks @clauderic! - Initial public release.
2912350 Thanks @clauderic! - Initial public release.2912350]:
Export DragDropEvents and allow them to be generic
a4f5fc3 Thanks @github-actions! - - Update DragDropEventHandlers types to be non nullable.
DragDropEvents and allow them to be genericDragDropProvider to be passed Data as a generic569b6e3, a176848, f13cbc9]:
#1656 569b6e3 Thanks @github-actions! - Export SortableKeyboardPlugin and OptimisticSortingPlugin from the sortable module to allow consumers to customize their sortable plugin configurations.
#1655 a176848 Thanks @blancham! - Fixed a bug where auto-scroll does not wotk with inverted element
Updated dependencies [f13cbc9]:
f13cbc9]:
#1656 f13cbc9 Thanks @github-actions! - Add a new initialization-pending status to the drag operation lifecycle. This status is set after a dragOperation is initiated but before the beforedragstart event fires, which allows consumers to prevent a drag operation from being initialized. This provides better control over the drag operation lifecycle and enables cancellation of drag operations before they are initialized.
Updated dependencies []:
2bb3065 Thanks @clauderic! - No longer setting pointer-events to none for DragOverlay component as it interferes with custom cursors.
bf04b2b Thanks @clauderic! - Allow nullish values to be passed to useSensors for conditional sensors.
### Patch Changes - Updated dependencies \[]: - @dnd-kit/state@0.1.0
23d694b Thanks @MateusJabour! - Exports sensors from @dnd-kit/dom through @dnd-kit/react#1645 043c280 Thanks @clauderic! - Add fallback logic to type-guards when instance checks fail to identify instances, for example to test if an element is an Element or HTMLElement or SVGElement, or if an AnimationEffect is a KeyframeEffect.
#1644 ee40aac Thanks @github-actions! - Feedback: Use revert instead of unset to reset styles applied by the popover attribute.
#1643 635d94f Thanks @clauderic! - Fix a bug in the Scroller plugin that would always use document.getElementFromPoint instead of the document of the source element.
#1644 0235cef Thanks @github-actions! - Cursor: Ensure styles for Cursor plugin are added to the document of the draggable source element.
#1644 1ba8700 Thanks @github-actions! - Fixed a bug in the getDocument helper to make it work with SVG elements.
#1644 3080d2c Thanks @github-actions! - Feedback: Set popover attribute value to manual.
Updated dependencies [00a33c9]:
00a33c9]:
00a33c9 Thanks @MateusJabour! - Adds new data property to Collision type7bd4568 #30 - Initial beta release, authored by @clauderic.7bd4568]:
Your coding agent can read these notes before it upgrades. Set up the MCP server →