Skip to content

Commit

Permalink
Fix selection clearer ref passed to motion.div (#31469)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed May 4, 2021
1 parent 791c8fc commit d176475
Showing 1 changed file with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,18 @@ import { useRefEffect } from '@wordpress/compose';
import { store as blockEditorStore } from '../../store';

export function useBlockSelectionClearer( onlySelfClicks = false ) {
const hasSelection = useSelect( ( select ) => {
const { hasSelectedBlock, hasMultiSelection } = select(
blockEditorStore
);

return hasSelectedBlock() || hasMultiSelection();
} );
const { hasSelectedBlock, hasMultiSelection } = useSelect(
blockEditorStore
);
const { clearSelectedBlock } = useDispatch( blockEditorStore );

return useRefEffect(
( node ) => {
if ( ! hasSelection ) {
return;
}

function onMouseDown( event ) {
if ( ! hasSelectedBlock() && ! hasMultiSelection() ) {
return;
}

// Only handle clicks on the canvas, not the content.
if (
event.target.closest( '.wp-block' ) ||
Expand All @@ -43,7 +39,7 @@ export function useBlockSelectionClearer( onlySelfClicks = false ) {
node.removeEventListener( 'mousedown', onMouseDown );
};
},
[ hasSelection, clearSelectedBlock ]
[ hasSelectedBlock, hasMultiSelection, clearSelectedBlock ]
);
}

Expand Down

0 comments on commit d176475

Please sign in to comment.