Skip to content

Commit

Permalink
Fix drop zone indicators for non blocks (#25986)
Browse files Browse the repository at this point in the history
* Remove isDraggingBlocks check

* Clean up drag and drop data if the user presses escape when dragging

* Add comment to ensure avoidance of dragend

* Switch to using dragend
  • Loading branch information
talldan authored Oct 22, 2020
1 parent 79e57cc commit 55bf7ec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
9 changes: 2 additions & 7 deletions packages/block-editor/src/components/block-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ function Items( {
hasMultiSelection,
getGlobalBlockCount,
isTyping,
isDraggingBlocks,
__experimentalGetActiveBlockIdByBlockNames,
} = select( 'core/block-editor' );

Expand All @@ -93,7 +92,6 @@ function Items( {
enableAnimation:
! isTyping() &&
getGlobalBlockCount() <= BLOCK_ANIMATION_THRESHOLD,
isDraggingBlocks: isDraggingBlocks(),
activeEntityBlockId,
};
}
Expand All @@ -105,7 +103,6 @@ function Items( {
orientation,
hasMultiSelection,
enableAnimation,
isDraggingBlocks,
activeEntityBlockId,
} = useSelect( selector, [ rootClientId ] );

Expand All @@ -114,8 +111,7 @@ function Items( {
rootClientId,
} );

const isAppenderDropTarget =
dropTargetIndex === blockClientIds.length && isDraggingBlocks;
const isAppenderDropTarget = dropTargetIndex === blockClientIds.length;

return (
<>
Expand All @@ -124,8 +120,7 @@ function Items( {
? multiSelectedBlockClientIds.includes( clientId )
: selectedBlockClientId === clientId;

const isDropTarget =
dropTargetIndex === index && isDraggingBlocks;
const isDropTarget = dropTargetIndex === index;

return (
<AsyncModeProvider
Expand Down
5 changes: 5 additions & 0 deletions packages/components/src/drop-zone/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,18 @@ class DropZoneProvider extends Component {
const { defaultView } = ownerDocument;
defaultView.addEventListener( 'dragover', this.onDragOver );
defaultView.addEventListener( 'mouseup', this.resetDragState );
// Note that `dragend` doesn't fire consistently for file and HTML drag
// events where the drag origin is outside the browser window.
// In Firefox it may also not fire if the originating node is removed.
defaultView.addEventListener( 'dragend', this.resetDragState );
}

componentWillUnmount() {
const { ownerDocument } = this.ref.current;
const { defaultView } = ownerDocument;
defaultView.removeEventListener( 'dragover', this.onDragOver );
defaultView.removeEventListener( 'mouseup', this.resetDragState );
defaultView.removeEventListener( 'dragend', this.resetDragState );
}

addDropZone( dropZone ) {
Expand Down

0 comments on commit 55bf7ec

Please sign in to comment.