diff --git a/core/src/components/input/input.tsx b/core/src/components/input/input.tsx index 6498eeffa4e..1c540467181 100644 --- a/core/src/components/input/input.tsx +++ b/core/src/components/input/input.tsx @@ -3,7 +3,13 @@ import { Build, Component, Element, Event, Host, Method, Prop, State, Watch, for import type { LegacyFormController, NotchController } from '@utils/forms'; import { createLegacyFormController, createNotchController } from '@utils/forms'; import type { Attributes } from '@utils/helpers'; -import { inheritAriaAttributes, debounceEvent, findItemLabel, inheritAttributes } from '@utils/helpers'; +import { + inheritAriaAttributes, + debounceEvent, + findItemLabel, + inheritAttributes, + componentOnReady, +} from '@utils/helpers'; import { printIonWarning } from '@utils/logging'; import { createSlotMutationController } from '@utils/slot-mutation-controller'; import type { SlotMutationController } from '@utils/slot-mutation-controller'; @@ -430,7 +436,14 @@ export class Input implements ComponentInterface { * Returns the native `` element used under the hood. */ @Method() - getInputElement(): Promise { + async getInputElement(): Promise { + /** + * If this gets called in certain early lifecycle hooks (ex: Vue onMounted), + * nativeInput won't be defined yet with the custom elements build, so wait for it to load in. + */ + if (!this.nativeInput) { + await new Promise((resolve) => componentOnReady(this.el, resolve)); + } return Promise.resolve(this.nativeInput!); } diff --git a/core/src/components/searchbar/searchbar.tsx b/core/src/components/searchbar/searchbar.tsx index 7fab6590e43..84ae9b2acc6 100644 --- a/core/src/components/searchbar/searchbar.tsx +++ b/core/src/components/searchbar/searchbar.tsx @@ -1,6 +1,6 @@ import type { ComponentInterface, EventEmitter } from '@stencil/core'; import { Component, Element, Event, Host, Method, Prop, State, Watch, forceUpdate, h } from '@stencil/core'; -import { debounceEvent, raf } from '@utils/helpers'; +import { debounceEvent, raf, componentOnReady } from '@utils/helpers'; import { isRTL } from '@utils/rtl'; import { createColorClasses } from '@utils/theme'; import { arrowBackSharp, closeCircle, closeSharp, searchOutline, searchSharp } from 'ionicons/icons'; @@ -269,7 +269,14 @@ export class Searchbar implements ComponentInterface { * Returns the native `` element used under the hood. */ @Method() - getInputElement(): Promise { + async getInputElement(): Promise { + /** + * If this gets called in certain early lifecycle hooks (ex: Vue onMounted), + * nativeInput won't be defined yet with the custom elements build, so wait for it to load in. + */ + if (!this.nativeInput) { + await new Promise((resolve) => componentOnReady(this.el, resolve)); + } return Promise.resolve(this.nativeInput!); } diff --git a/core/src/components/textarea/textarea.tsx b/core/src/components/textarea/textarea.tsx index b78121d97d2..6159f64790d 100644 --- a/core/src/components/textarea/textarea.tsx +++ b/core/src/components/textarea/textarea.tsx @@ -16,7 +16,13 @@ import { import type { LegacyFormController, NotchController } from '@utils/forms'; import { createLegacyFormController, createNotchController } from '@utils/forms'; import type { Attributes } from '@utils/helpers'; -import { inheritAriaAttributes, debounceEvent, findItemLabel, inheritAttributes } from '@utils/helpers'; +import { + inheritAriaAttributes, + debounceEvent, + findItemLabel, + inheritAttributes, + componentOnReady, +} from '@utils/helpers'; import { printIonWarning } from '@utils/logging'; import { createSlotMutationController } from '@utils/slot-mutation-controller'; import type { SlotMutationController } from '@utils/slot-mutation-controller'; @@ -378,7 +384,14 @@ export class Textarea implements ComponentInterface { * Returns the native `