DndGrid
Main grid layout component.
Import
import { DndGrid } from "@dnd-grid/react";Need a headless wrapper? Use useDndGrid to build your
own container while keeping the same drag/resize behavior.
For breakpoint layouts, use ResponsiveDndGrid.
If you already have a measured width, pass width.
Props
Core props
layoutLayoutDefault: []Grid layout state (position and size per item). Missing entries are derived from children (with a dev warning).
childrenReactNoderequiredGrid items; each child key must match a layout id.
Measurement
widthnumberOptional container width in pixels. When provided, measurement is skipped.
measureBeforeMountbooleanDefault: trueDelay rendering until the container width is measured.
initialWidthnumberDefault: 1280Width used before measurement when rendering early.
containerPropsHTMLAttributes<HTMLDivElement>Props applied to the measurement wrapper.
Grid configuration
colsnumberDefault: 12Number of columns.
rowHeightnumberDefault: 150Row height in pixels.
gapnumber | { top: number; right: number; bottom: number; left: number }Default: 10Gap between items. Use a number or { top, right, bottom, left }.
containerPaddingnumber | { top: number; right: number; bottom: number; left: number } | nullDefault: nullContainer padding. Use a number or { top, right, bottom, left }. If null,
uses the gap value.
autoSizebooleanDefault: trueResize container height to fit content.
maxRowsnumberDefault: InfinityMaximum rows.
Behaviour
draggablebooleanDefault: trueEnable dragging for all items. Can be overridden per item.
resizablebooleanDefault: trueEnable resizing for all items. Can be overridden per item.
autoScrollboolean | AutoScrollOptionsDefault: trueAuto-scroll near scroll edges. Use true for defaults or pass options.
boundedbooleanDefault: falseKeep items within bounds during drag.
compactorCompactorCompaction strategy and collision behaviour.
constraintsLayoutConstraint[]Drag and resize constraints. Defaults to defaultConstraints.
validationbooleanDefault: true in dev, false in prodValidate layouts at runtime with Zod. Disable to avoid extra work in hot paths.
callbackThrottlenumber | { drag?: number; resize?: number }Throttle onDrag and onResize callbacks in milliseconds. Pass a number to
apply to both, or an object for per-callback control.
Motion
animationConfigAnimationConfigConfigure spring and shadow animations for drag, resize, and settling.
reducedMotionReducedMotionSetting | booleanMotion preference override. Use "system" to respect
prefers-reduced-motion.
Accessibility
liveAnnouncementsLiveAnnouncementsOptions | falseConfigure aria-live announcements for drag, resize, and focus. Pass false to
disable.
aria-labelstringAccessible label for the grid container.
aria-labelledbystringID of the element that labels the grid.
aria-describedbystringID of the element that describes the grid.
Drag configuration
dragHandlestringSelector for elements that start a drag.
dragCancelstringSelector for elements that cancel a drag.
dragTouchDelayDurationnumberDefault: 250Touch delay in milliseconds.
Resize configuration
resizeHandlesResizeHandleAxis[]Default: ["se"]Edges and corners that show resize handles.
resizeHandleReactElement | ((axis, ref) => ReactElement)Custom resize handle component.
Drop configuration
Drop behavior is enabled when you provide onDrop or onDropDragOver.
droppingItemPartial<LayoutItem>Defaults for the dropped item.
Transform
transformScalenumberDefault: 1Scale factor for CSS transforms.
Styling
classNamestringExtra CSS class for the container.
styleCSSPropertiesInline styles for the container.
slotPropsSlotPropsCustomize className and style for items, placeholders, and resize handles.
innerRefRef<HTMLDivElement>Ref to the container element.
Callbacks
| Callback | Description |
|---|---|
onLayoutChange | Fires when the layout changes. |
onDragStart | Fires when dragging starts. |
onDrag | Fires while dragging. |
onDragEnd | Fires when dragging ends. |
onResizeStart | Fires when resizing starts. |
onResize | Fires while resizing. |
onResizeEnd | Fires when resizing ends. |
onDrop | Fires when an external item is dropped. |
onDropDragOver | Fires when an external item is dragged over the grid. |