diff --git a/packages/block-editor/src/utils/dom.js b/packages/block-editor/src/utils/dom.js index 0603e9bbb1db9..e30f809e38779 100644 --- a/packages/block-editor/src/utils/dom.js +++ b/packages/block-editor/src/utils/dom.js @@ -162,15 +162,14 @@ export function getVisibleElementBounds( element ) { let currentElement; while ( ( currentElement = stack.pop() ) ) { - for ( const child of currentElement.children ) { - if ( isElementVisible( child ) ) { - let childBounds = child.getBoundingClientRect(); - // If the parent is scrollable, use parent's scrollable bounds. - if ( isScrollable( currentElement ) ) { - childBounds = currentElement.getBoundingClientRect(); + // Children won’t affect bounds unless the element is not scrollable. + if ( ! isScrollable( currentElement ) ) { + for ( const child of currentElement.children ) { + if ( isElementVisible( child ) ) { + const childBounds = child.getBoundingClientRect(); + bounds = rectUnion( bounds, childBounds ); + stack.push( child ); } - bounds = rectUnion( bounds, childBounds ); - stack.push( child ); } } }