11import  {  defineCustomElement  }  from  "@ionic/core/components/ion-tab-bar.js" ; 
2- import  type  {  VNode  }  from  "vue" ; 
2+ import  type  {  VNode ,   Ref  }  from  "vue" ; 
33import  {  h ,  defineComponent ,  getCurrentInstance ,  inject  }  from  "vue" ; 
44
55// TODO(FW-2969): types 
@@ -16,6 +16,12 @@ interface Tab {
1616  ref : VNode ; 
1717} 
1818
19+ interface  TabBarData  { 
20+   hasRouterOutlet : boolean ; 
21+   _tabsWillChange : Function ; 
22+   _tabsDidChange : Function ; 
23+ } 
24+ 
1925const  isTabButton  =  ( child : any )  =>  child . type ?. name  ===  "IonTabButton" ; 
2026
2127const  getTabs  =  ( nodes : VNode [ ] )  =>  { 
@@ -34,28 +40,31 @@ const getTabs = (nodes: VNode[]) => {
3440
3541export  const  IonTabBar  =  defineComponent ( { 
3642  name : "IonTabBar" , 
37-   props : { 
38-     /* eslint-disable @typescript-eslint/no-empty-function */ 
39-     _tabsWillChange : {  type : Function ,  default : ( )  =>  { }  } , 
40-     _tabsDidChange : {  type : Function ,  default : ( )  =>  { }  } , 
41-     _hasRouterOutlet : {  type : Boolean ,  default : false  } , 
42-     /* eslint-enable @typescript-eslint/no-empty-function */ 
43-   } , 
4443  data ( )  { 
4544    return  { 
4645      tabState : { 
4746        activeTab : undefined , 
4847        tabs : { } , 
48+         /** 
49+          * Passing this prop to each tab button 
50+          * lets it be aware of the presence of 
51+          * the router outlet. 
52+          */ 
53+         hasRouterOutlet : false , 
4954      } , 
5055      tabVnodes : [ ] , 
56+       /* eslint-disable @typescript-eslint/no-empty-function */ 
57+       _tabsWillChange : {  type : Function ,  default : ( )  =>  { }  } , 
58+       _tabsDidChange : {  type : Function ,  default : ( )  =>  { }  } , 
59+       /* eslint-enable @typescript-eslint/no-empty-function */ 
5160    } ; 
5261  } , 
5362  updated ( )  { 
5463    this . setupTabState ( inject ( "navManager" ,  null ) ) ; 
5564  } , 
5665  methods : { 
5766    setupTabState ( ionRouter : any )  { 
58-       const  hasRouterOutlet  =  this . $props  . _hasRouterOutlet ; 
67+       const  hasRouterOutlet  =  this . $data  . tabState . hasRouterOutlet ; 
5968      /** 
6069       * For each tab, we need to keep track of its 
6170       * base href as well as any child page that 
@@ -75,13 +84,6 @@ export const IonTabBar = defineComponent({
7584          ref : child , 
7685        } ; 
7786
78-         /** 
79-          * Passing this prop to each tab button 
80-          * lets it be aware of the presence of 
81-          * the router outlet. 
82-          */ 
83-         tabState . hasRouterOutlet  =  hasRouterOutlet ; 
84- 
8587        /** 
8688         * Passing this prop to each tab button 
8789         * lets it be aware of the state that 
@@ -126,7 +128,7 @@ export const IonTabBar = defineComponent({
126128     * @param  ionRouter 
127129     */ 
128130    checkActiveTab ( ionRouter : any )  { 
129-       const  hasRouterOutlet  =  this . $props  . _hasRouterOutlet ; 
131+       const  hasRouterOutlet  =  this . $data  . tabState . hasRouterOutlet ; 
130132      const  currentRoute  =  ionRouter ?. getCurrentRouteInfo ( ) ; 
131133      const  childNodes  =  this . $data . tabVnodes ; 
132134      const  {  tabs,  activeTab : prevActiveTab  }  =  this . $data . tabState ; 
@@ -216,7 +218,7 @@ export const IonTabBar = defineComponent({
216218      this . tabSwitch ( activeTab ) ; 
217219    } , 
218220    tabSwitch ( activeTab : string ,  ionRouter ?: any )  { 
219-       const  hasRouterOutlet  =  this . $props  . _hasRouterOutlet ; 
221+       const  hasRouterOutlet  =  this . $data  . tabState . hasRouterOutlet ; 
220222      const  childNodes  =  this . $data . tabVnodes ; 
221223      const  {  activeTab : prevActiveTab  }  =  this . $data . tabState ; 
222224      const  tabState  =  this . $data . tabState ; 
@@ -227,15 +229,15 @@ export const IonTabBar = defineComponent({
227229      const  tabDidChange  =  activeTab  !==  prevActiveTab ; 
228230      if  ( tabBar )  { 
229231        if  ( activeChild )  { 
230-           tabDidChange  &&  this . $props  . _tabsWillChange ( activeTab ) ; 
232+           tabDidChange  &&  this . $data  . _tabsWillChange ( activeTab ) ; 
231233
232234          if  ( hasRouterOutlet  &&  ionRouter  !==  null )  { 
233235            ionRouter . handleSetCurrentTab ( activeTab ) ; 
234236          } 
235237
236238          tabBar . selectedTab  =  tabState . activeTab  =  activeTab ; 
237239
238-           tabDidChange  &&  this . $props  . _tabsDidChange ( activeTab ) ; 
240+           tabDidChange  &&  this . $data  . _tabsDidChange ( activeTab ) ; 
239241        }  else  { 
240242          /** 
241243           * When going to a tab that does 
@@ -250,6 +252,17 @@ export const IonTabBar = defineComponent({
250252  } , 
251253  mounted ( )  { 
252254    const  ionRouter : any  =  inject ( "navManager" ,  null ) ; 
255+     /** 
256+      * Tab bar can be used as a standalone component, 
257+      * so it cannot be modified directly through 
258+      * IonTabs. Instead, data will be passed through 
259+      * the provide/inject. 
260+      */ 
261+     const  tabBarData  =  inject < Ref < TabBarData > > ( "tabBarData" ) ; 
262+ 
263+     this . $data . tabState . hasRouterOutlet  =  tabBarData . value . hasRouterOutlet ; 
264+     this . $data . _tabsWillChange  =  tabBarData . value . _tabsWillChange ; 
265+     this . $data . _tabsDidChange  =  tabBarData . value . _tabsDidChange ; 
253266
254267    this . setupTabState ( ionRouter ) ; 
255268
0 commit comments