Skip to content

feat(dnd): pass keys and draggedKey as arguments to renderDropIndicator #8459

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

reidbarber
Copy link
Member

@reidbarber reidbarber commented Jun 26, 2025

Closes #8410

Open to discussion on API/naming and if we want both of these.

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

Try new story: https://reactspectrum.blob.core.windows.net/reactspectrum/e55eb5de291f8362ca0d011454cef157d9f36fa6/storybook/index.html?path=/story/react-aria-components--list-box-dnd-custom-drop-indicator&providerSwitcher-express=false

(not sure why the styles are broken in that story on the build, but they're also broken in the other listbox dnd story on main)

🧢 Your Project:

@rspbot
Copy link

rspbot commented Jun 26, 2025

Copy link
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I keyboard drag, every drop indicator appears in the storybook example

@@ -181,6 +181,70 @@ ListBoxDnd.story = {
}
};

export const ListBoxDndCustomDropIndicator = (props: ListBoxProps<typeof albums[0]>) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this story a little nicer, each image takes up so much of my screen that it's hard to use
it'd be really cool if we could use the image in the custom drop indicator as well, I feel like that'd be more true to life/the use case that was asked for. Wonder how hard it'd be to add the animations as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the styles broke in #8272 and they're fine locally, just broken on the build. I'll try to improve the preview, just wanted to show that the keys and draggedKey were correct

@rspbot
Copy link

rspbot commented Jun 27, 2025

@rspbot
Copy link

rspbot commented Jun 27, 2025

## 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> = () => []
   isDisabled?: boolean
   onDragEnd?: (DraggableCollectionEndEvent) => void
   onDragMove?: (DraggableCollectionMoveEvent) => void
   onDragStart?: (DraggableCollectionStartEvent) => void
   onDrop?: (DroppableCollectionDropEvent) => 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
+  renderDropIndicator?: (DropTarget, Set<Key>, Key) => JSX.Element
   shouldAcceptItemDrop?: (ItemDropTarget, DragTypes) => boolean
 }

Copy link
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Behavior looks good to me, just one small comment. Happy for it to go in as it is though

@@ -59,7 +59,7 @@ interface DropHooks {
useDroppableCollection?: (props: DroppableCollectionOptions, state: DroppableCollectionState, ref: RefObject<HTMLElement | null>) => DroppableCollectionResult,
useDroppableItem?: (options: DroppableItemOptions, state: DroppableCollectionState, ref: RefObject<HTMLElement | null>) => DroppableItemResult,
useDropIndicator?: (props: AriaDropIndicatorProps, state: DroppableCollectionState, ref: RefObject<HTMLElement | null>) => DropIndicatorAria,
renderDropIndicator?: (target: DropTarget) => JSX.Element,
renderDropIndicator?: (target: DropTarget, keys: Set<Key>, draggedKey?: Key) => JSX.Element,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the API is fine, its consistent with things like renderPreview. One small nit would be to perhaps make keys optional instead since we won't have access to keys/draggedKeys if the user is dropping from Finder for example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose dragged items on renderDropIndicator function in useDragAndDrop
4 participants