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

Components

The component layer — a thin shell in the react-grid-layout style over the factories. <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 factories. 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/svelte.

GridLayout

The turnkey controlled grid. Each item’s content comes from an item snippet (Svelte has no keyed-children analog), keyed by the layout item’s i. It supplies its own DragDropProvider; nest several (or wrap them in SnapGridGroup) and they share one.

<GridLayout {layout} {width} onLayoutChange={(next) => (layout = next)} gridConfig={{ cols: 12, rowHeight: 60, margin: [12, 12] }} resizeConfig={{ handles: ["se", "e", "s"] }} > {#snippet item(it)} <div>{it.i}</div> {/snippet} </GridLayout>

Props

PropTypeDefaultDescription
layoutLayoutRequired. Controlled array of items. Never mutated.
widthnumberRequired. Container width in px (from createContainerWidth).
itemSnippet<[LayoutItem]>Required. Renders each item’s content; receives the item’s current (reflowed) entry.
onLayoutChange(layout: Layout) => voidCalled with the next layout when an interaction commits.
gridConfigPartial<GridConfig>see GridConfigColumns, row height, margins, padding, maxRows.
dragConfigDragConfigDrag behaviour.
resizeConfigResizeConfig{ handles: ["se"] }Resize behaviour.
dropConfigDropConfig{ enabled: false }Accept external draggables.
accept(source) => booleandnd-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.
idstringautoStable id for the droppable surface.
onDragStart onDrag onDragStopGridEventCallbackDrag lifecycle.
onResizeStart onResize onResizeStopGridEventCallbackResize lifecycle.
onDrop(layout, item, event) => voidFired when an external draggable is dropped in.
classstringAppended to snapgrid.
stylestringMerged after (and able to override) the surface’s positioning style.

ResponsiveGridLayout

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

Props

PropTypeDefaultDescription
widthnumberRequired. Container width in px.
layoutsResponsiveLayoutsRequired. Per-breakpoint layout map.
itemSnippet<[LayoutItem]>Required. Renders each item’s content (keyed by i).
onLayoutChange(layout, layouts) => voidActive layout and the updated map.
onBreakpointChange(breakpoint, cols) => voidFired 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 class styleAs on GridLayout.

GridItem

A positioned tile with stable classes (snapgrid-item, data-grid-id, data-dragging) and the configured resize handles. Svelte’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.

PropTypeDescription
idstringRequired. Matches the layout item’s i.
groupstringRequired. The owning grid’s id (from its createGridContainer).
childrenSnippetTile content.
classstringAppended to snapgrid-item.
stylestringMerged after (and able to override) the positioning style.

GridPlaceholder

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

PropTypeDescription
groupstringRequired. The owning grid’s id.
classstringAppended to snapgrid-placeholder.
stylestringMerged after (and able to override) the default look.

SnapGridGroup

Shares one dnd-kit DragDropProvider across several sibling grids so tiles can be dragged between them. Takes only a children snippet — 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