From 132c597e81abfa0c73c05d14755fb43f47c7aee8 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Mon, 23 Oct 2023 16:32:54 +0200 Subject: [PATCH] MOBILE-4362 quiz: Fix wrong renderization of ddwtos in some cases --- src/addons/qtype/ddwtos/classes/ddwtos.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/addons/qtype/ddwtos/classes/ddwtos.ts b/src/addons/qtype/ddwtos/classes/ddwtos.ts index a06ac29280f..2133ecb2641 100644 --- a/src/addons/qtype/ddwtos/classes/ddwtos.ts +++ b/src/addons/qtype/ddwtos/classes/ddwtos.ts @@ -480,17 +480,23 @@ export class AddonQtypeDdwtosQuestion { return; } - await CoreDom.waitToBeInDOM(groupItems[0]); - - let maxWidth = 0; - let maxHeight = 0; - // Find max height and width. groupItems.forEach((item) => { item.innerHTML = CoreTextUtils.decodeHTML(item.innerHTML); }); + // Wait to render in order to calculate size. - await CoreUtils.nextTick(); + if (groupItems[0].parentElement) { + // Wait for parent to be visible. We cannot wait for group items because they have visibility hidden. + await CoreDom.waitToBeVisible(groupItems[0].parentElement); + } else { + // Group items should always have a parent, add a fallback just in case. + await CoreDom.waitToBeInDOM(groupItems[0]); + await CoreUtils.nextTicks(5); + } + // Find max height and width. + let maxWidth = 0; + let maxHeight = 0; groupItems.forEach((item) => { maxWidth = Math.max(maxWidth, Math.ceil(item.offsetWidth)); maxHeight = Math.max(maxHeight, Math.ceil(item.offsetHeight));