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.
main
Noel De Martin 2023-10-11 10:25:02 +02:00
parent aebbe3365c
commit 781a4da551
1 changed files with 6 additions and 2 deletions

View File

@ -123,8 +123,12 @@ export class CoreDom {
* @returns True if element is visible inside the DOM. * @returns True if element is visible inside the DOM.
*/ */
static isElementVisible(element: HTMLElement, checkSize = true): boolean { static isElementVisible(element: HTMLElement, checkSize = true): boolean {
if (checkSize && (element.clientWidth === 0 || element.clientHeight === 0)) { if (checkSize) {
return false; const dimensions = element.getBoundingClientRect();
if (dimensions.width === 0 || dimensions.height === 0) {
return false;
}
} }
const style = getComputedStyle(element); const style = getComputedStyle(element);