Docs/API
makeDragArea
Rules for the drags that start inside an element — an axis, bounds, a grid, auto-scroll, activation — under one app-wide provider.
function makeDragArea( target: MaybeElementRef, options?: DragAreaOptions,): DragAreaReturn;Makes an element a drag area: the drags that start inside it (draggables and sortable items) follow its rules, see DragAreaOptions. One provider can then serve the whole app, with boards, canvases and feeds that drag their own way. The closest area wins when areas are nested.
const board = useTemplateRef<HTMLElement>('board');
makeDragArea(board, { restrictToArea: true, modifiers: [snapToGrid(24)] });
Inner areas inherit disabled; every other rule comes from the closest area. See
Axes, bounds and grids.
The chips inside the area follow its rules; the one outside it drags freely.
Loading the demo…
<script setup lang="ts">
import { DnDProvider } from '@vue-dnd-kit/core';
import AreaDesk from './AreaDesk.vue';
</script>
<template>
<!-- One provider for everything: the area changes the rules only for the drags that start in it. -->
<DnDProvider>
<AreaDesk />
</DnDProvider>
</template>Options
Options of makeDragArea: rules for the drags that start inside the area's element (draggables and sortable items alike), so one provider can serve the whole app while parts of the page drag their own way. The closest area wins when areas are nested.
Every option takes a value, a ref or a getter and is read when it is needed: when a press starts (activation, disabled) or when the drag starts.
'x' | 'y'value · ref · getterLocks the drags to one axis, after the modifiers. A draggable's own axis (or its list's) wins.
Modifier[]value · ref · getterModifiers for the drags, after the provider's and before the draggable's own (or its list's): e.g. [snapToGrid(20)] for a board.
booleanvalue · ref · gettertrue: the drags stay inside the area's element (after the modifiers, before the axis lock).
boolean | AutoScrollOptionsvalue · ref · getterOverrides the provider's autoScroll for the area's scroll container: the element itself, or its closest scrollable ancestor. false turns it off there. Unlike the other options it applies to every drag that scrolls the container, wherever it started.
ActivationOptionsvalue · ref · getterActivation of the drags per pointer kind, between the draggable's own (which wins) and the provider's: e.g. a longer touch press in a scrolling feed.
booleanvalue · ref · gettertrue: no drag starts in the area, nor in the areas inside it (unlike the other options, which come from the closest area). Its draggables report aria-disabled.
Returns
What makeDragArea returns.
ComputedRef<boolean>A drag that started in this area is running (until its drop is decided).
ComputedRef<boolean>Auto-scroll is moving the area's scroll container (the element, or its closest scrollable ancestor).