Skip to content

Commit

Permalink
Handle more deeply nested blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
mattheu committed Oct 30, 2023
1 parent c349f15 commit 02a2916
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ const InnerBlockSliderControlled = ( {
const {
slideBlocks,
selectedBlockId,
hasSelectedInnerBlock,
getLowestCommonAncestorWithSelectedBlock,
} = useSelect(
( select ) => {
const blockEditorStore = select( 'core/block-editor' );
return {
slideBlocks: blockEditorStore.getBlock( parentBlockId ).innerBlocks,
selectedBlockId: blockEditorStore.getSelectedBlockClientId(),
hasSelectedInnerBlock: blockEditorStore.hasSelectedInnerBlock,
getLowestCommonAncestorWithSelectedBlock: blockEditorStore.getLowestCommonAncestorWithSelectedBlock,
};
}
);
Expand Down Expand Up @@ -89,13 +89,13 @@ const InnerBlockSliderControlled = ( {
*/
useEffect( () => {
const found = slideBlocks.findIndex( ( slideBlock ) => {
return slideBlock.clientId === selectedBlockId || hasSelectedInnerBlock( slideBlock.clientId );
return getLowestCommonAncestorWithSelectedBlock( slideBlock.clientId ) === slideBlock.clientId;
} );

if ( found >= 0 ) {
setCurrentItemIndex( found );
}
}, [ selectedBlockId, slideBlocks, setCurrentItemIndex, hasSelectedInnerBlock ] );
}, [ selectedBlockId, slideBlocks, setCurrentItemIndex, getLowestCommonAncestorWithSelectedBlock ] );

return (
<div className="inner-block-slider">
Expand Down

0 comments on commit 02a2916

Please sign in to comment.