From 876d539b37a1bb5630747aad211755614f85a4ba Mon Sep 17 00:00:00 2001 From: Aodhagan Murphy <109096340+aodhagan-cf@users.noreply.github.com> Date: Thu, 28 Nov 2024 13:06:00 +0000 Subject: [PATCH] fix: not hiding elements that share borders [TOL-2545] (#965) --- .../src/inspectorMode/utils.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/live-preview-sdk/src/inspectorMode/utils.ts b/packages/live-preview-sdk/src/inspectorMode/utils.ts index 16d56415..ae844cfd 100644 --- a/packages/live-preview-sdk/src/inspectorMode/utils.ts +++ b/packages/live-preview-sdk/src/inspectorMode/utils.ts @@ -360,13 +360,16 @@ export function getAllTaggedEntries({ const isElementOverlapped = (element: Element, coordinates: DOMRect, root = window.document) => { const { top, right, bottom, left } = coordinates; - const topLeft = root.elementFromPoint(left, top); - const topRight = root.elementFromPoint(right, top); - const bottomLeft = root.elementFromPoint(left, bottom); - const bottomRight = root.elementFromPoint(right, bottom); - - return ( - topLeft === element || topRight === element || bottomLeft === element || bottomRight === element + const topLeft = root.elementFromPoint(left + 1, top + 1); + const topRight = root.elementFromPoint(right - 1, top + 1); + const bottomLeft = root.elementFromPoint(left + 1, bottom - 1); + const bottomRight = root.elementFromPoint(right - 1, bottom - 1); + + return !( + topLeft === element && + topRight === element && + bottomLeft === element && + bottomRight === element ); }; @@ -380,7 +383,7 @@ const addVisibilityToTaggedElements = ( checkOpacity: true, checkVisibilityCSS: true, }), - isCoveredByOtherElement: !isElementOverlapped( + isCoveredByOtherElement: isElementOverlapped( taggedElement.element!, taggedElement.coordinates!, root,