From 5edd745e6e824d80d5a36ee618599314d82a5ea5 Mon Sep 17 00:00:00 2001 From: Mitchell Austin Date: Mon, 28 Oct 2024 11:25:25 -0700 Subject: [PATCH] Skip children of elements that are scrollable --- packages/block-editor/src/utils/dom.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/block-editor/src/utils/dom.js b/packages/block-editor/src/utils/dom.js index 0603e9bbb1db96..e30f809e387797 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 ); } } }