diff --git a/src/addons/calendar/components/reminder-time-modal/reminder-time-modal.html b/src/addons/calendar/components/reminder-time-modal/reminder-time-modal.html index 052241aa9..1071b92d9 100644 --- a/src/addons/calendar/components/reminder-time-modal/reminder-time-modal.html +++ b/src/addons/calendar/components/reminder-time-modal/reminder-time-modal.html @@ -34,7 +34,7 @@ - +
diff --git a/src/addons/calendar/components/reminder-time-modal/reminder-time-modal.ts b/src/addons/calendar/components/reminder-time-modal/reminder-time-modal.ts index 871530664..1a10a9c27 100644 --- a/src/addons/calendar/components/reminder-time-modal/reminder-time-modal.ts +++ b/src/addons/calendar/components/reminder-time-modal/reminder-time-modal.ts @@ -15,7 +15,6 @@ import { AddonCalendar, AddonCalendarReminderUnits, AddonCalendarValueAndUnit } from '@addons/calendar/services/calendar'; import { Component, Input, OnInit } from '@angular/core'; import { CoreDomUtils } from '@services/utils/dom'; -import { CoreUtils } from '@services/utils/utils'; import { ModalController } from '@singletons'; /** @@ -166,11 +165,9 @@ export class AddonCalendarReminderTimeModalComponent implements OnInit { this.radioValue = 'custom'; - await CoreUtils.nextTick(); - - const target = ev.target; - if (target && 'focus' in target) { - target.focus(); + const target = ev.target; + if (target) { + CoreDomUtils.focusElement(target); } } diff --git a/src/core/directives/auto-focus.ts b/src/core/directives/auto-focus.ts index 9a37a208f..d84252ad6 100644 --- a/src/core/directives/auto-focus.ts +++ b/src/core/directives/auto-focus.ts @@ -49,19 +49,7 @@ export class CoreAutoFocusDirective implements AfterViewInit { await CoreDom.waitToBeInDOM(this.element); - let focusElement = this.element; - - if ('getInputElement' in focusElement) { - // If it's an Ionic element get the right input to use. - focusElement.componentOnReady && await focusElement.componentOnReady(); - focusElement = await focusElement.getInputElement(); - } - - if (!focusElement) { - return; - } - - CoreDomUtils.focusElement(focusElement); + CoreDomUtils.focusElement(this.element); } diff --git a/src/core/services/utils/dom.ts b/src/core/services/utils/dom.ts index b42da0973..9d2bc991a 100644 --- a/src/core/services/utils/dom.ts +++ b/src/core/services/utils/dom.ts @@ -336,12 +336,22 @@ export class CoreDomUtilsProvider { /** * Focus an element and open keyboard. * - * @param focusElement HTML element to focus. + * @param element HTML element to focus. */ - async focusElement(focusElement: HTMLElement): Promise { + async focusElement( + element: HTMLIonInputElement | HTMLIonTextareaElement | HTMLIonSearchbarElement | HTMLElement, + ): Promise { let retries = 10; - if (!focusElement.focus) { + let focusElement = element; + + if ('getInputElement' in focusElement) { + // If it's an Ionic element get the right input to use. + focusElement.componentOnReady && await focusElement.componentOnReady(); + focusElement = await focusElement.getInputElement(); + } + + if (!focusElement || !focusElement.focus) { throw new CoreError('Element to focus cannot be focused'); }