Docs/API
makeSelectionArea
A rubber band that selects the draggables it touches — drag one of them and the whole selection travels.
function makeSelectionArea( target: MaybeElementRef, options?: SelectionAreaOptions,): SelectionAreaReturn;Makes an element a rubber-band selection area for the draggables inside it. Render the rectangle yourself: <div v-if="isSelecting" class="band" :style="style" />.
<script setup lang="ts">
const area = useTemplateRef<HTMLElement>('area');
const { isSelecting, style } = makeSelectionArea(area);
</script>
<template>
<div ref="area" class="area">
<!-- items -->
<div v-if="isSelecting" class="band" :style="style" />
</div>
</template>
A press on the empty space of the area starts the band. See Multi-drag and selection.
Loading the demo…
<script setup lang="ts">
import { DnDProvider } from '@vue-dnd-kit/core';
import ShapeBoard from './ShapeBoard.vue';
</script>
<template>
<DnDProvider>
<ShapeBoard />
</DnDProvider>
</template>Options
Options of makeSelectionArea. The band selects into the provider's selection, the one multi-drag and selected read (useDnD().selection). modifier, strategy, accept and disabled take a value, a ref or a getter (accept: a value or a ref, a function is a rule) and are read when a press starts a band; turning disabled on also cancels a running one.
SelectionModifiervalue · ref · getterKeys that must be held for a press to draw a band. Default: none, any press on the empty space draws.
SelectionStrategyvalue · ref · getterDefault 'toggle'.
AcceptRulevalue · refWhich draggables the band selects; the matcher of drop targets.
booleanvalue · ref · gettertrue: presses draw no band.
(ids: Key[]) => voidThe band ended: gets every id selected now.
Returns
What makeSelectionArea returns.
ComputedRef<boolean>A band is being drawn: render it then.
ComputedRef<Record<string, string>>Style for the selection rectangle element (absolute, container-relative).
Values
'toggle': items the band crosses flip their state from before the band;'select': only the items inside the band are selected.
type SelectionStrategy = 'toggle' | 'select'