From 781a4da551a4712109ebf7d05634a73205fb4db8 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Wed, 11 Oct 2023 10:25:02 +0200 Subject: [PATCH] MOBILE-4362 core: Fix isElementVisible helper Some elements return 0 for clientWidth even if they have a size in the final rendering, so we'll use getBoundingClientRect which is more reliable. --- src/core/singletons/dom.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/singletons/dom.ts b/src/core/singletons/dom.ts index a969e6463..eb3798944 100644 --- a/src/core/singletons/dom.ts +++ b/src/core/singletons/dom.ts @@ -123,8 +123,12 @@ export class CoreDom { * @returns True if element is visible inside the DOM. */ static isElementVisible(element: HTMLElement, checkSize = true): boolean { - if (checkSize && (element.clientWidth === 0 || element.clientHeight === 0)) { - return false; + if (checkSize) { + const dimensions = element.getBoundingClientRect(); + + if (dimensions.width === 0 || dimensions.height === 0) { + return false; + } } const style = getComputedStyle(element);