Components
The component layer — a thin shell in the react-grid-layout style over the
composables. <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 composables. 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/vue.
GridLayout
The turnkey controlled grid. Each item’s content comes from the item scoped slot (Vue has no
keyed-children analog), rendered once per layout entry and keyed by the item’s i. It supplies its
own DragDropProvider unless one already encloses it; nest several (or wrap them in
SnapGridGroup) and they share one.
<script setup>
import { ref } from "vue";
import { GridLayout } from "@snapgridjs/vue";
const layout = ref([
{ i: "a", x: 0, y: 0, w: 2, h: 2 },
{ i: "b", x: 2, y: 0, w: 2, h: 2 },
]);
</script>
<template>
<GridLayout
:layout="layout"
:width="1024"
:grid-config="{ cols: 12, rowHeight: 60, margin: [12, 12] }"
:resize-config="{ handles: ['se', 'e', 's'] }"
@layout-change="layout = $event"
>
<template #item="{ item }">
<div>{{ item.i }}</div>
</template>
</GridLayout>
</template>The item slot receives the committed layout entry — the one you passed in layout, not the
reflowed preview. A tile’s live (reflowed) entry during a drag comes from
useGridItem().item.
The callbacks below are ordinary props, so bind them either way: :on-layout-change="fn" or the
equivalent listener syntax @layout-change="fn".
Props
| Prop | Type | Default | Description |
|---|---|---|---|
layout | Layout | — | Required. Controlled array of items. Never mutated. |
width | number | — | Required. Container width in px (from useContainerWidth). |
onLayoutChange | (layout: Layout) => void | — | Called with the next layout when an interaction commits. |
gridConfig | Partial<GridConfig> | see GridConfig | Columns, row height, margins, padding, maxRows. |
dragConfig | DragConfig | — | Drag behaviour. |
resizeConfig | ResizeConfig | { handles: ["se"] } | Resize behaviour. |
dropConfig | DropConfig | { enabled: false } | Accept external draggables. |
accept | (source) => boolean | — | dnd-kit interop: also accept a foreign sortable as a drop target. |
compactor | Compactor | verticalCompactor | Packing algorithm. |
isDraggable | boolean | true | Grid-level drag toggle. |
isResizable | boolean | true | Grid-level resize toggle. |
autoSize | boolean | true | Grow the container height to fit content. |
id | string | auto | Stable id for the droppable surface; surfaced back as the tiles’ group. |
type | string | "grid" | The droppable surface’s dnd-kit type. |
onDragStart onDrag onDragStop | GridEventCallback | — | Drag lifecycle. |
onResizeStart onResize onResizeStop | GridEventCallback | — | Resize lifecycle. |
onDrop | (layout, item, event) => void | — | Fired when an external draggable is dropped in. |
Slots & attributes
| Description | |
|---|---|
#item="{ item }" | Required. Renders each item’s content; receives the committed layout entry. |
class | Fallthrough attribute — appended to snapgrid. |
style | Fallthrough attribute — merged after (and able to override) the surface’s positioning style. |
ResponsiveGridLayout
Switches columns and layout by breakpoint as width changes. See
Responsive layouts.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
width | number | — | Required. Container width in px. |
layouts | ResponsiveLayouts | — | 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. |
breakpoints | Breakpoints | DEFAULT_BREAKPOINTS | Breakpoint → min width (px). |
cols | BreakpointCols | DEFAULT_BREAKPOINT_COLS | Breakpoint → column count. |
rowHeight | number | 150 | Row height in px. |
margin | [number, number] | [10, 10] | Gap between items. |
containerPadding | [number, number] | null | null | Surface padding; falls back to margin. |
compactor dragConfig resizeConfig isDraggable isResizable autoSize | As on GridLayout. |
Item content comes from the same #item="{ item }" scoped slot, and class / style fall through
as on GridLayout. 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. Vue’s 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.
| Prop | Type | Description |
|---|---|---|
id | string | Required. Matches the layout item’s i. |
group | string | Required. The owning grid’s id (from its useGridContainer). |
| Description | |
|---|---|
| default slot | Tile content. |
class | Fallthrough attribute — appended to snapgrid-item. |
style | Fallthrough attribute — merged 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 useGridPlaceholder for full
control.
| Prop | Type | Description |
|---|---|---|
group | string | Required. The owning grid’s id. |
| Description | |
|---|---|
class | Fallthrough attribute — appended to snapgrid-placeholder. |
style | Fallthrough attribute — merged 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 default slot — a thin wrapper over DragDropProvider (nesting GridLayouts
already shares a provider, so this is just explicit), and it honors an enclosing provider of your
own. See Cross-grid dragging.
Item ids must be unique across all grids that share a provider.