-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix: Update Tree drag and drop focus #9751
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
Changes from 2 commits
89b1ddf
ab126bf
9b06359
85d042f
f23442a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ import { | |
| clearGlobalDnDState, | ||
| DIRECTORY_DRAG_TYPE, | ||
| droppableCollectionMap, | ||
| getItemElement, | ||
| getTypes, | ||
| globalDndState, | ||
| isInternalDropOperation, | ||
|
|
@@ -273,6 +274,25 @@ export function useDroppableCollection(props: DroppableCollectionOptions, state: | |
| first = item.parentKey; | ||
| } | ||
|
|
||
| if (item?.type === 'content') { | ||
| let parentKey = item.parentKey; | ||
| while (parentKey) { | ||
| let parent = state.collection.getItem(parentKey); | ||
| if (parent?.type !== 'item') { | ||
| parentKey = parent?.parentKey; | ||
| continue; | ||
| } | ||
| // If an item doesn't exist in the collection, | ||
| // it's because its parent is collapsed, and we should focus its parent instead. | ||
| let item = getItemElement(ref, parentKey); | ||
|
||
| if (item) { | ||
| first = parentKey; | ||
| break; | ||
| } | ||
| parentKey = parent.parentKey; | ||
| } | ||
| } | ||
|
|
||
| // eslint-disable-next-line max-depth | ||
| if (first != null) { | ||
| state.selectionManager.setFocusedKey(first); | ||
|
|
@@ -312,7 +332,7 @@ export function useDroppableCollection(props: DroppableCollectionOptions, state: | |
|
|
||
| state.selectionManager.setFocused(true); | ||
| } | ||
| }, [localState]); | ||
| }, [localState, ref]); | ||
|
|
||
| let onDrop = useCallback((e: DropEvent, target: DropTarget) => { | ||
| let {state} = localState; | ||
|
|
||
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.
would you mind commenting the code here?