diff --git a/core/src/components/tab/tab.tsx b/core/src/components/tab/tab.tsx index 769f086765..474c563cfa 100644 --- a/core/src/components/tab/tab.tsx +++ b/core/src/components/tab/tab.tsx @@ -1,4 +1,4 @@ -import { Build, Component, ComponentInterface, Element, Host, Method, Prop, h } from '@stencil/core'; +import { Build, Component, ComponentInterface, Element, Host, Method, Prop, Watch, h } from '@stencil/core'; import { ComponentRef, FrameworkDelegate } from '../../interface'; import { attachComponent } from '../../utils/framework-delegate'; @@ -30,7 +30,7 @@ export class Tab implements ComponentInterface { */ @Prop() component?: ComponentRef; - componentWillLoad() { + async componentWillLoad() { if (Build.isDev) { if (this.component !== undefined && this.el.childElementCount > 0) { console.error('You can not use a lazy-loaded component in a tab and inlined content at the same time.' + @@ -39,6 +39,9 @@ export class Tab implements ComponentInterface { `- Remove the embedded content inside the ion-tab: `); } } + if (this.active) { + await this.setActive(); + } } /** Set the active component for the tab */ @@ -48,6 +51,13 @@ export class Tab implements ComponentInterface { this.active = true; } + @Watch('active') + changeActive(isActive: boolean) { + if (isActive) { + this.prepareLazyLoaded(); + } + } + private prepareLazyLoaded(): Promise { if (!this.loaded && this.component != null) { this.loaded = true; diff --git a/core/src/components/tabs/tabs.tsx b/core/src/components/tabs/tabs.tsx index e269ae9d44..fce60622fa 100644 --- a/core/src/components/tabs/tabs.tsx +++ b/core/src/components/tabs/tabs.tsx @@ -46,7 +46,9 @@ export class Tabs implements NavOutlet { } if (!this.useRouter) { const tabs = this.tabs; - await this.select(tabs[0]); + if (tabs.length > 0) { + await this.select(tabs[0]); + } } this.ionNavWillLoad.emit(); } @@ -127,7 +129,8 @@ export class Tabs implements NavOutlet { this.leavingTab = this.selectedTab; this.selectedTab = selectedTab; this.ionTabsWillChange.emit({ tab: selectedTab.tab }); - return selectedTab.setActive(); + selectedTab.active = true; + return Promise.resolve(); } private tabSwitch() { diff --git a/core/src/components/tabs/test/standalone/index.html b/core/src/components/tabs/test/standalone/index.html index 84730218ef..f84ce8c62b 100644 --- a/core/src/components/tabs/test/standalone/index.html +++ b/core/src/components/tabs/test/standalone/index.html @@ -12,7 +12,7 @@ - +
@@ -71,11 +71,11 @@ diff --git a/core/src/utils/gesture/pointer-events.ts b/core/src/utils/gesture/pointer-events.ts index 48540f4328..e27cdae054 100644 --- a/core/src/utils/gesture/pointer-events.ts +++ b/core/src/utils/gesture/pointer-events.ts @@ -92,8 +92,8 @@ export const createPointerEvents = ( stopMouse(); }; - const enable = (enable = true) => { - if (!enable) { + const enable = (isEnabled = true) => { + if (!isEnabled) { if (rmTouchStart) { rmTouchStart(); }