diff --git a/ionic/components/tabs/tabs.ts b/ionic/components/tabs/tabs.ts index 4dcfd643b3..05b86c0f3f 100644 --- a/ionic/components/tabs/tabs.ts +++ b/ionic/components/tabs/tabs.ts @@ -217,15 +217,36 @@ export class Tabs extends Ion { /** * @private - * "Touch" the active tab, either going back to the root view of the tab - * or scrolling the tab to the top + * "Touch" the active tab, going back to the root view of the tab + * or optionally letting the tab handle the event */ touchActive(tab) { + let active = tab.getActive(); + + if(!active) { + return Promise.resolve(); + } + + let instance = active.instance; + + // If they have a custom tab selected handler, call it + if(instance.tabSelected) { + return instance.tabSelected(); + } + + // If we're a few pages deep, pop to root if (tab.length() > 1) { // Pop to the root view return tab.popToRoot(); } + // Otherwise, if the page we're on is not our real root, reset it to our + // default root type + if(tab.root != active.componentType) { + return tab.setRoot(tab.root); + } + + // And failing all of that, we do something safe and secure return Promise.resolve(); }