Skip to content

Commit

Permalink
fix(tabs): do not init w/ tab that is hidden or disabled
Browse files Browse the repository at this point in the history
Closes #6226
  • Loading branch information
adamdbradley committed Apr 19, 2016
1 parent 8eedb2b commit 8d8cc4c
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion ionic/components/tabs/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,30 @@ export class Tabs extends Ion {
* @private
*/
ngAfterContentInit() {
let preloadTabs = (isBlank(this.preloadTabs) ? this._config.getBoolean('preloadTabs') : isTrueProperty(this.preloadTabs));

// get the selected index
let selectedIndex = this.selectedIndex ? parseInt(this.selectedIndex, 10) : 0;

let preloadTabs = (isBlank(this.preloadTabs) ? this._config.getBoolean('preloadTabs') : isTrueProperty(this.preloadTabs));
// ensure the selectedIndex isn't a hidden or disabled tab
// also find the first available index incase we need it later
let availableIndex = -1;
this._tabs.forEach((tab, index) => {
if (tab.enabled && tab.show && availableIndex < 0) {
// we know this tab index is safe to show
availableIndex = index;
}

if (index === selectedIndex && (!tab.enabled || !tab.show)) {
// the selectedIndex is not safe to show
selectedIndex = -1;
}
});
if (selectedIndex < 0) {
// the selected index wasn't safe to show
// instead use an available index found to be safe to show
selectedIndex = availableIndex;
}

this._tabs.forEach((tab, index) => {
if (index === selectedIndex) {
Expand Down

0 comments on commit 8d8cc4c

Please sign in to comment.