fix(tabs): do not init w/ tab that is hidden or disabled

Closes #6226
This commit is contained in:
Adam Bradley
2016-04-19 11:27:34 -05:00
parent 8eedb2b463
commit 8d8cc4c097

View File

@@ -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) {