Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion packages/@react-aria/dnd/src/DragManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import {announce} from '@react-aria/live-announcer';
import {ariaHideOutside} from '@react-aria/overlays';
import {DragEndEvent, DragItem, DropActivateEvent, DropEnterEvent, DropEvent, DropExitEvent, DropItem, DropOperation, DropTarget as DroppableCollectionTarget, FocusableElement} from '@react-types/shared';
import {flushSync} from 'react-dom';
import {getDragModality, getTypes} from './utils';
import {getInteractionModality} from '@react-aria/interactions';
import type {LocalizedStringFormatter} from '@internationalized/string';
Expand Down Expand Up @@ -494,7 +495,16 @@ class DragSession {

// Blur and re-focus the drop target so that the focus ring appears.
if (this.currentDropTarget) {
this.currentDropTarget.element.blur();
// Since we cancel all focus events in drag sessions, refire blur to make sure state gets updated so drag target doesn't think it's still focused
// i.e. When you from one list to another during a drag session, we need the blur to fire on the first list after the drag.
if (!this.dragTarget.element.contains(this.currentDropTarget.element)) {
this.dragTarget.element.dispatchEvent(new FocusEvent('blur'));
this.dragTarget.element.dispatchEvent(new FocusEvent('focusout', {bubbles: true}));
Comment on lines +501 to +502
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just wanna double check, but the blur is strictly for the original drag target (e.g. the row) and the focusout is for the benefit of the Virtualizer's onBlur?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, exactly

}
// Re-focus the focusedKey upon reorder. This requires a React rerender between blurring and focusing.
flushSync(() => {
this.currentDropTarget.element.blur();
});
this.currentDropTarget.element.focus();
}

Expand Down
11 changes: 7 additions & 4 deletions packages/@react-spectrum/list/stories/ListView.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,10 @@ export function DragIntoItemExample(props) {
}

export function DragBetweenListsExample(props) {
let onDropAction = action('onDrop');
let {onDragStart, onDragEnd, onDrop} = props;
onDrop = chain(action('onDrop'), onDrop);
onDragStart = chain(action('dragStart'), onDragStart);
onDragEnd = chain(action('dragEnd'), onDragEnd);

let list1 = useListData({
initialItems: props.items1 || itemList1
Expand Down Expand Up @@ -898,8 +901,8 @@ export function DragBetweenListsExample(props) {
getAllowedDropOperationsAction();
return ['move', 'cancel'];
},
onDragStart: action('dragStart'),
onDragEnd: action('dragEnd')
onDragStart,
onDragEnd
});

// Use a random drag type so the items can only be reordered within the two lists and not dragged elsewhere.
Expand All @@ -923,7 +926,7 @@ export function DragBetweenListsExample(props) {
}
}
}
onDropAction(e);
onDrop(e);
onMove(keys, e.target);
}
},
Expand Down
Loading