useDraggableCollectionState

Manages state for a draggable collection.

installyarn add react-stately
version3.35.0
usageimport {useDraggableCollectionState} from 'react-stately'

API#


useDraggableCollectionState( (props: )):

Interface#


Properties

NameTypeDescription
collection<<unknown>>A collection of items.
selectionManagerAn interface for reading and updating multiple selection state.
draggedKeyKeynullThe key of the item that initiated a drag.
draggingKeysSet<Key>The keys of the items that are currently being dragged.
isDisabledbooleanWhether drag events are disabled.
preview<null>The ref of the element that will be rendered as the drag preview while dragging.
getAllowedDropOperations() => []Function that returns the drop operations that are allowed for the dragged items. If not provided, all drop operations are allowed.

Methods

MethodDescription
isDragging( (key: Key )): booleanReturns whether the given key is currently being dragged.
getKeysForDrag( (key: Key )): Set<Key>Returns the keys of the items that will be dragged with the given key (e.g. selected items).
getItems( (key: Key )): []Returns the items to drag for the given key.
startDrag( (key: Key, , event: )): voidBegins a drag for the given key. This triggers the onDragStart event.
moveDrag( (event: )): voidTriggers an onDragMove event.
endDrag( (event: )): voidEnds the current drag, and emits an onDragEnd event.

Example#


See the docs for useDraggableCollection in react-aria for an example of useDraggableCollectionState.