Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions packages/react-aria-components/src/DragAndDrop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export function useDndPersistedKeys(selectionManager: MultipleSelectionManager,
if (dropState.target.dropPosition === 'after') {
// Normalize to the "before" drop position since we only render those to the DOM.
let nextKey = dropState.collection.getKeyAfter(dropTargetKey);
let lastDescendantKey: Key | null = null;
if (nextKey != null) {
let targetLevel = dropState.collection.getItem(dropTargetKey)?.level ?? 0;
// Skip over any rows that are descendants of the target ("after" position should be after all children)
Expand All @@ -85,16 +86,26 @@ export function useDndPersistedKeys(selectionManager: MultipleSelectionManager,
if (!node) {
break;
}
// Stop once we find a node at the same level or higher
// Skip over non-item nodes (e.g., loaders) since they can't be drop targets.
// eslint-disable-next-line max-depth
if (node.type !== 'item') {
nextKey = dropState.collection.getKeyAfter(nextKey);
continue;
}

// Stop once we find an item at the same level or higher
// eslint-disable-next-line max-depth
if ((node.level ?? 0) <= targetLevel) {
break;
}

lastDescendantKey = nextKey;
nextKey = dropState.collection.getKeyAfter(nextKey);
}
}

dropTargetKey = nextKey ?? dropTargetKey;
// If nextKey is null (end of collection), use the last descendant
dropTargetKey = nextKey ?? lastDescendantKey ?? dropTargetKey;
}
}

Expand Down