useDraggableCollectionState
Manages state for a draggable collection.
install | yarn add react-stately |
---|---|
version | 3.39.0 |
usage | import {useDraggableCollectionState} from 'react-stately' |
API#
useDraggableCollectionState(
(props: DraggableCollectionStateOptions
)): DraggableCollectionState
Interface#
Properties
Name | Type | Description |
collection | Collection<Node<unknown>> | A collection of items. |
selectionManager | MultipleSelectionManager | An interface for reading and updating multiple selection state. |
draggedKey | Key | null | The key of the item that initiated a drag. |
draggingKeys | Set<Key> | The keys of the items that are currently being dragged. |
isDisabled | boolean | Whether drag events are disabled. |
preview | RefObject<DragPreviewRenderer | null> | The ref of the element that will be rendered as the drag preview while dragging. |
getAllowedDropOperations | () => DropOperation[] | Function that returns the drop operations that are allowed for the dragged items. If not provided, all drop operations are allowed. |
getPreviewOffset | (
(options: { | A function that returns the offset of the drag preview relative to the pointer. If not provided, a default offset is automatically calculated based on the click/touch position, falling back to the center of the preview in cases where the preview is smaller than the interaction point. |
Methods
Method | Description |
isDragging(
(key: Key
)): boolean | Returns 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
)): DragItem[] | Returns the items to drag for the given key. |
startDrag(
(key: Key,
, event: DragStartEvent
)): void | Begins a drag for the given key. This triggers the onDragStart event. |
moveDrag(
(event: DragMoveEvent
)): void | Triggers an onDragMove event. |
endDrag(
(event: DraggableCollectionEndEvent
)): void | Ends the current drag, and emits an onDragEnd event. |
Example#
See the docs for useDraggableCollection in react-aria for an example of useDraggableCollectionState
.