Skip to content

Commit

Permalink
Block: try merging effects (#19617)
Browse files Browse the repository at this point in the history
* Block: try merging effects

* Merge multi selected effect
  • Loading branch information
ellatrix committed Jan 14, 2020
1 parent d89119d commit 5338c47
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,30 +174,27 @@ function BlockListBlock( {

// Focus the selected block's wrapper or inner input on mount and update
const isMounting = useRef( true );
useEffect( () => {
if ( isSelected && ! isMultiSelecting && ! isNavigationMode ) {
focusTabbable( ! isMounting.current );
}
isMounting.current = false;
}, [ isSelected, isMultiSelecting, isNavigationMode ] );

// Focus the first multi selected block
useEffect( () => {
if ( isFirstMultiSelected ) {
wrapper.current.focus();
if ( ! isMultiSelecting && ! isNavigationMode ) {
if ( isSelected ) {
focusTabbable( ! isMounting.current );
} else if ( isFirstMultiSelected ) {
wrapper.current.focus();
}
}
}, [ isFirstMultiSelected ] );

isMounting.current = false;
}, [
isSelected,
isFirstMultiSelected,
isMultiSelecting,
isNavigationMode,
] );

// Block Reordering animation
const animationStyle = useMovingAnimation( wrapper, isSelected || isPartOfMultiSelection, isSelected || isFirstMultiSelected, enableAnimation, animateOnChange );

// Focus the first editable or the wrapper if edit mode.
useLayoutEffect( () => {
if ( isSelected && ! isNavigationMode ) {
focusTabbable( true );
}
}, [ isSelected, isNavigationMode ] );

// Other event handlers

/**
Expand Down

0 comments on commit 5338c47

Please sign in to comment.