From ed5c8ebf09f35d389ea1d5e91a2abbc501020721 Mon Sep 17 00:00:00 2001 From: "Manu Mtz.-Almeida" Date: Sun, 19 Aug 2018 18:58:46 +0200 Subject: [PATCH] perf(overlay): prevent layout thrashing --- core/src/utils/overlays.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/core/src/utils/overlays.ts b/core/src/utils/overlays.ts index 7c1a7ee9c0..eb4edfcdb0 100644 --- a/core/src/utils/overlays.ts +++ b/core/src/utils/overlays.ts @@ -100,12 +100,6 @@ async function overlayAnimation( baseEl: HTMLElement, opts: any ): Promise { - if (overlay.keyboardClose) { - const activeElement = baseEl.ownerDocument.activeElement as HTMLElement; - if (activeElement) { - activeElement.blur(); - } - } if (overlay.animation) { overlay.animation.destroy(); overlay.animation = undefined; @@ -117,6 +111,14 @@ async function overlayAnimation( if (!overlay.willAnimate) { animation.duration(0); } + if (overlay.keyboardClose) { + animation.beforeAddWrite(() => { + const activeElement = baseEl.ownerDocument.activeElement as HTMLElement; + if (activeElement && activeElement.matches('input, ion-input, ion-textarea')) { + activeElement.blur(); + } + }); + } await animation.playAsync(); animation.destroy();