feat(useDraggable): add public facing hook #7356
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
FYI: All commits will be squashed into one final commit, with any relevant issues also linked.
Proposed behaviour
This PR introduces a comprehensive drag-and-drop system built on top of Atlassian's Pragmatic Drag & Drop library.
The implementation provides a flexible, reusable solution for creating draggable lists with automatic reordering capabilities.
Consumers can now use the
useDraggable
hook which will be externally available to make any array of React Elements draggable.Key Components Added:
Core Architecture:
DraggableContainer
- Main container component that manages drag operations and list stateDraggableItem
- Individual draggable item wrapper with drop target capabilitiesuseDraggable
- Hook that simplifies usage by wrapping items automaticallyKey Features:
Dual Drag Modes:
continuous
- Items reorder in real-time as user dragsonDrop
- Items only reorder when dropped (better performance for large lists)Smart State Management:
Robust ID Handling:
Imperative API:
reOrder(itemId, toIndex)
method for programmatic movesEdge Detection:
Technical Implementation:
@atlaskit/pragmatic-drag-and-drop
for reliable cross-browser supportuseImperativeHandle
for external controlBenefits:
useImperativeHandle
can be used for manual re-ordering. Supporting graceful degradation.This implementation provides a production-ready drag-and-drop solution that can be easily integrated into existing components while maintaining full control over styling and behavior.
Current behaviour
Currently, consumers have to use third-party draggable libraries to build out draggable functionality. Internally, we use and re-use
react-dnd
which is now out of support and results in code repetition and complexity.Checklist
d.ts
file added or updated if requiredQA
Additional context
Testing instructions