diff --git a/core/src/utils/overlays.ts b/core/src/utils/overlays.ts index 7c1a7ee9c01..eb4edfcdb0f 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();