Skip to content

Commit

Permalink
Conditionally bind block event handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jan 4, 2020
1 parent d72b361 commit 47a414f
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,9 @@ function BlockListBlock( {
const onKeyDown = ( event ) => {
const { keyCode, target } = event;

// ENTER/BACKSPACE Shortcuts are only available if the wrapper is focused
// and the block is not locked.
const canUseShortcuts = (
isSelected &&
! isLocked &&
( target === wrapper.current || target === breadcrumb.current )
);
// ENTER/BACKSPACE Shortcuts are only available if the wrapper or
// breadcrumb is focused.
const canUseShortcuts = ( target === wrapper.current || target === breadcrumb.current );
const isEditMode = ! isNavigationMode;

switch ( keyCode ) {
Expand Down Expand Up @@ -266,7 +262,7 @@ function BlockListBlock( {
// cases where Firefox might always set `buttons` to `0`.
// See https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons
// See https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/which
if ( isSelected && ( buttons || which ) === 1 ) {
if ( ( buttons || which ) === 1 ) {
onSelectionStart( clientId );
}
};
Expand Down Expand Up @@ -407,7 +403,8 @@ function BlockListBlock( {
ref={ wrapper }
className={ wrapperClassName }
data-type={ name }
onKeyDown={ onKeyDown }
// Only allow shortcuts when a blocks is selected and not locked.
onKeyDown={ isSelected && ! isLocked ? onKeyDown : undefined }
tabIndex="0"
aria-label={ blockLabel }
role="group"
Expand Down Expand Up @@ -476,7 +473,8 @@ function BlockListBlock( {
{ /* eslint-disable-next-line jsx-a11y/no-static-element-interactions */ }
<div
ref={ blockNodeRef }
onMouseLeave={ onMouseLeave }
// Only allow selection to be started from a selected block.
onMouseLeave={ isSelected ? onMouseLeave : undefined }
data-block={ clientId }
>
<BlockCrashBoundary onError={ onBlockError }>
Expand Down

0 comments on commit 47a414f

Please sign in to comment.