-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat(dnd): pass draggedKey into getItems #8448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Build successful! 🎉 |
@@ -65,7 +65,7 @@ export interface DragAndDropOptions extends Omit<DraggableCollectionProps, 'prev | |||
* A function that returns the items being dragged. If not specified, we assume that the collection is not draggable. | |||
* @default () => [] | |||
*/ | |||
getItems?: (keys: Set<Key>) => DragItem[], | |||
getItems?: (keys: Set<Key>, draggedKey: Key) => DragItem[], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should add to the jsdocs what that second argument is
Build successful! 🎉 |
@@ -63,6 +63,8 @@ export interface DragAndDropHooks { | |||
export interface DragAndDropOptions extends Omit<DraggableCollectionProps, 'preview' | 'getItems'>, Omit<DroppableCollectionProps, 'onMove'> { | |||
/** | |||
* A function that returns the items being dragged. If not specified, we assume that the collection is not draggable. | |||
* @param keys - The set of keys that will be affected by the drag (e.g. the current selection). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the goal is to decouple, then should this say something like
* @param keys - The set of keys that will be affected by the drag (e.g. the current selection). | |
* @param keys - The set of keys that can be affected by the drag (e.g. the current selection). |
or if it's always the selection
* @param keys - The currently selected keys, or, if no selection, equivalent to the dragged key.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe best not to use the @param
? I'm not seeing it in the docs? https://reactspectrum.blob.core.windows.net/reactspectrum/5ddddffe6cfa57d0840bc8d3c8f6d0b8db961b3d/docs/react-aria/useDraggableCollection.html
This reverts commit 5ddddff.
Build successful! 🎉 |
## API Changes
react-aria-components/react-aria-components:DragAndDropOptions DragAndDropOptions {
acceptedDragTypes?: 'all' | Array<string | symbol> = 'all'
dropTargetDelegate?: DropTargetDelegate
getAllowedDropOperations?: () => Array<DropOperation>
getDropOperation?: (DropTarget, DragTypes, Array<DropOperation>) => DropOperation
- getItems?: (Set<Key>) => Array<DragItem> = () => []
+ getItems?: (Set<Key>, Key) => Array<DragItem> = () => []
isDisabled?: boolean
onDragEnd?: (DraggableCollectionEndEvent) => void
onDragMove?: (DraggableCollectionMoveEvent) => void
onDragStart?: (DraggableCollectionStartEvent) => void
onDropActivate?: (DroppableCollectionActivateEvent) => void
onDropEnter?: (DroppableCollectionEnterEvent) => void
onDropExit?: (DroppableCollectionExitEvent) => void
onInsert?: (DroppableCollectionInsertDropEvent) => void
onItemDrop?: (DroppableCollectionOnItemDropEvent) => void
onMove?: (DroppableCollectionReorderEvent) => void
onReorder?: (DroppableCollectionReorderEvent) => void
onRootDrop?: (DroppableCollectionRootDropEvent) => void
renderDragPreview?: (Array<DragItem>) => JSX.Element
renderDropIndicator?: (DropTarget) => JSX.Element
shouldAcceptItemDrop?: (ItemDropTarget, DragTypes) => boolean
} @react-spectrum/dnd/@react-spectrum/dnd:DragAndDropOptions DragAndDropOptions {
acceptedDragTypes?: 'all' | Array<string | symbol> = 'all'
getAllowedDropOperations?: () => Array<DropOperation>
getDropOperation?: (DropTarget, DragTypes, Array<DropOperation>) => DropOperation
- getItems?: (Set<Key>) => Array<DragItem> = () => []
+ getItems?: (Set<Key>, Key) => Array<DragItem> = () => []
onDragEnd?: (DraggableCollectionEndEvent) => void
onDragMove?: (DraggableCollectionMoveEvent) => void
onDragStart?: (DraggableCollectionStartEvent) => void
onDrop?: (DroppableCollectionDropEvent) => void
onDropEnter?: (DroppableCollectionEnterEvent) => void
onDropExit?: (DroppableCollectionExitEvent) => void
onInsert?: (DroppableCollectionInsertDropEvent) => void
onItemDrop?: (DroppableCollectionOnItemDropEvent) => void
onReorder?: (DroppableCollectionReorderEvent) => void
onRootDrop?: (DroppableCollectionRootDropEvent) => void
renderPreview?: (Set<Key>, Key) => JSX.Element
shouldAcceptItemDrop?: (ItemDropTarget, DragTypes) => boolean
} @react-stately/dnd/@react-stately/dnd:DraggableCollectionStateOptions DraggableCollectionStateOptions {
collection: Collection<Node<unknown>>
getAllowedDropOperations?: () => Array<DropOperation>
- getItems: (Set<Key>) => Array<DragItem>
+ getItems: (Set<Key>, Key) => Array<DragItem>
isDisabled?: boolean
onDragEnd?: (DraggableCollectionEndEvent) => void
onDragMove?: (DraggableCollectionMoveEvent) => void
onDragStart?: (DraggableCollectionStartEvent) => void
selectionManager: MultipleSelectionManager
} |
@@ -65,7 +65,12 @@ export interface DragAndDropOptions extends Omit<DraggableCollectionProps, 'prev | |||
* A function that returns the items being dragged. If not specified, we assume that the collection is not draggable. | |||
* @default () => [] | |||
*/ | |||
getItems?: (keys: Set<Key>) => DragItem[], | |||
getItems?: ( | |||
/** The set of keys that can be affected by the drag (e.g. the current selection). */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the individual ones are useful for autofill. But they still don't appear in our docs. Are you seeing them somewhere? maybe I'm just looking in the wrong place
https://reactspectrum.blob.core.windows.net/reactspectrum/a00898e3b00bd2f2ad3954a86d8e8df764b7623b/docs/react-aria/useDraggableCollection.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just in VSCode, not seeing them in the docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we should probably add it to the main description body for the prop as well. I think leave in the more granular ones for VSCode though as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for mouse/touch drag, but it seems like keyboard DnD still moves all the selected items. I guess that might be expected? Feels a bit inconsistent though
Closes #8162
By passing
draggedKey
as the second argument ofgetItems
, you can decouple your dragged items from selection.✅ Pull Request Checklist:
📝 Test Instructions:
Check test and new story
🧢 Your Project: