Skip to Content
New — snapgrid now ships for SolidJS: the same dnd-kit-native, headless-first grid — drag, resize, repack, and drag between grids. See it in Solid →

Components

The component layer — a thin shell in the react-grid-layout style over the hooks. <GridLayout> bundles the dnd-kit DragDropProvider, the container, the items, and the placeholder, so you never touch dnd-kit directly. For full control of the markup, or to compose with other dnd-kit draggables, use the hooks. See the Component layer guide for usage; this page is the prop reference.

A dragged tile floats itself, so there’s no overlay component to render at either layer. If you need a separate floating preview, dnd-kit’s DragOverlay is re-exported from @snapgridjs/solid.

GridLayout

The turnkey controlled grid. Each item’s content comes from a render-prop child (GridItemRenderer), called once per layout entry; tiles are keyed by the item’s i. It supplies its own DragDropProvider (and runs the surface in a child component, so it’s safe to use in the very component that renders it); nest several (or wrap them in SnapGridGroup) and they share one.

import { GridLayout, type Layout } from "@snapgridjs/solid"; import { createSignal } from "solid-js"; function Board() { const [layout, setLayout] = createSignal<Layout>([ { i: "a", x: 0, y: 0, w: 2, h: 2 }, { i: "b", x: 2, y: 0, w: 2, h: 2 }, ]); return ( <GridLayout layout={layout()} width={1024} onLayoutChange={setLayout} gridConfig={{ cols: 12, rowHeight: 60, margin: [12, 12] }} resizeConfig={{ handles: ["se", "e", "s"] }} > {(item) => <div>{item().i}</div>} </GridLayout> ); }

The child receives an accessor for the item’s committed layout entry — the one you passed in layout, not the reflowed preview. It’s called once per tile, so read item() inside JSX to stay reactive. A tile’s live (reflowed) entry during a drag comes from useGridItem().item.

Props (GridLayoutProps)

PropTypeDefaultDescription
layoutLayout—Required. Controlled array of items. Never mutated.
widthnumber—Required. Container width in px (from useContainerWidth).
onLayoutChange(layout: Layout) => void—Called with the next layout when an interaction commits.
gridConfigPartial<GridConfig>see GridConfigColumns, row height, margins, padding, maxRows.
dragConfigDragConfig—Drag behaviour.
resizeConfigResizeConfig{ handles: ["se"] }Resize behaviour.
dropConfigDropConfig{ enabled: false }Accept external draggables.
accept(source: DragSourceInfo) => boolean—dnd-kit interop: also accept a foreign sortable as a drop target.
compactorCompactorverticalCompactorPacking algorithm.
isDraggablebooleantrueGrid-level drag toggle.
isResizablebooleantrueGrid-level resize toggle.
autoSizebooleantrueGrow the container height to fit content.
idstringauto (createUniqueId)Stable id for the droppable surface; surfaced back as the tiles’ group.
typestring"grid"The droppable surface’s dnd-kit type.
onDragStart onDrag onDragStopGridEventCallback—Drag lifecycle.
onResizeStart onResize onResizeStopGridEventCallback—Resize lifecycle.
onDrop(layout, item, event) => void—Fired when an external draggable is dropped in.
childrenGridItemRenderer—Renders each item’s content: (item: Accessor<LayoutItem>) => JSX.Element.
classstring—Appended to snapgrid.
styleJSX.CSSProperties—Merged over (and able to override) the surface’s positioning style.

Other div attributes pass through to the surface element. The native HTML5 drag events are not among them: onDragStart / onDrag / onDrop are the grid’s own callbacks above.

ResponsiveGridLayout

Switches columns and layout by breakpoint as width changes. See Responsive layouts.

Props (ResponsiveGridLayoutProps)

PropTypeDefaultDescription
widthnumber—Required. Container width in px.
layoutsResponsiveLayouts—Required. Per-breakpoint layout map.
onLayoutChange(layout, layouts) => void—Active layout and the updated map.
onBreakpointChange(breakpoint, cols) => void—Fired when the active breakpoint changes.
breakpointsBreakpointsDEFAULT_BREAKPOINTSBreakpoint → min width (px).
colsBreakpointColsDEFAULT_BREAKPOINT_COLSBreakpoint → column count.
rowHeightnumber150Row height in px.
margin[number, number][10, 10]Gap between items.
containerPadding[number, number] | nullnullSurface padding; falls back to margin.
compactor dragConfig resizeConfig isDraggable isResizable autoSize children class styleAs on GridLayout.

Item content comes from the same render-prop child as GridLayout, and other div attributes pass through to the surface. This component deliberately doesn’t expose the grid id (or type): those attributes are dropped rather than forwarded, so two responsive grids in one SnapGridGroup can’t collide on a registry key.

GridItem

A positioned tile with stable classes (snapgrid-item, data-grid-id, data-dragging) and the item’s configured resize handles. Solid’s fine-grained reactivity updates only the tiles whose state changed, so there’s nothing to memoize. Use it inside your own surface, or let GridLayout create them. id and group are read once at setup (tiles are keyed by i).

Prop (GridItemProps)TypeDescription
idstringRequired. Matches the layout item’s i.
groupstringRequired. The owning grid’s id (from its useGridContainer).
childrenJSX.ElementTile content.
classstringAppended to snapgrid-item.
styleJSX.CSSPropertiesMerged over (and able to override) the positioning style.

Other div attributes pass through to the tile element.

GridPlaceholder

Renders the landing-cell marker, or nothing when idle. Takes the grid’s group. Customize with class / style, or use useGridPlaceholder for full control.

Prop (GridPlaceholderProps)TypeDescription
groupstringRequired. The owning grid’s id.
classstringAppended to snapgrid-placeholder.
styleJSX.CSSPropertiesMerged over (and able to override) the default look.

Other div attributes pass through to the placeholder element. It takes no children.

SnapGridGroup

Shares one dnd-kit DragDropProvider across several sibling grids so tiles can be dragged between them. Takes only children — a thin wrapper over DragDropProvider (nesting GridLayouts already shares a provider, so this is just explicit). See Cross-grid dragging.

Item ids must be unique across all grids that share a provider.

Last updated on