Skip to content

Commit 8d8cc4c

Browse files
committed
fix(tabs): do not init w/ tab that is hidden or disabled
Closes #6226
1 parent 8eedb2b commit 8d8cc4c

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

ionic/components/tabs/tabs.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,30 @@ export class Tabs extends Ion {
287287
* @private
288288
*/
289289
ngAfterContentInit() {
290+
let preloadTabs = (isBlank(this.preloadTabs) ? this._config.getBoolean('preloadTabs') : isTrueProperty(this.preloadTabs));
291+
292+
// get the selected index
290293
let selectedIndex = this.selectedIndex ? parseInt(this.selectedIndex, 10) : 0;
291294

292-
let preloadTabs = (isBlank(this.preloadTabs) ? this._config.getBoolean('preloadTabs') : isTrueProperty(this.preloadTabs));
295+
// ensure the selectedIndex isn't a hidden or disabled tab
296+
// also find the first available index incase we need it later
297+
let availableIndex = -1;
298+
this._tabs.forEach((tab, index) => {
299+
if (tab.enabled && tab.show && availableIndex < 0) {
300+
// we know this tab index is safe to show
301+
availableIndex = index;
302+
}
303+
304+
if (index === selectedIndex && (!tab.enabled || !tab.show)) {
305+
// the selectedIndex is not safe to show
306+
selectedIndex = -1;
307+
}
308+
});
309+
if (selectedIndex < 0) {
310+
// the selected index wasn't safe to show
311+
// instead use an available index found to be safe to show
312+
selectedIndex = availableIndex;
313+
}
293314

294315
this._tabs.forEach((tab, index) => {
295316
if (index === selectedIndex) {

0 commit comments

Comments
 (0)