Skip to content

Commit ac1a886

Browse files
committed
fix(tabs): ionChange is emitted after the tab is selected
fixes #10538
1 parent 0fa98b4 commit ac1a886

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/components/tabs/tabs.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { App } from '../app/app';
44
import { Config } from '../../config/config';
55
import { DeepLinker } from '../../navigation/deep-linker';
66
import { Ion } from '../ion';
7-
import { isBlank } from '../../util/util';
7+
import { isBlank, assert } from '../../util/util';
88
import { NavController } from '../../navigation/nav-controller';
99
import { NavControllerBase } from '../../navigation/nav-controller-base';
1010
import { getComponent, NavOptions, DIRECTION_SWITCH } from '../../navigation/nav-util';
@@ -408,14 +408,24 @@ export class Tabs extends Ion implements AfterViewInit {
408408
if (opts.updateUrl !== false) {
409409
this._linker.navChange(DIRECTION_SWITCH);
410410
}
411+
this._fireChangeEvent(selectedTab);
411412
});
413+
} else {
414+
this._fireChangeEvent(selectedTab);
412415
}
416+
}
417+
418+
_fireChangeEvent(selectedTab: Tab) {
419+
assert(this.getSelected() === selectedTab, 'selected tab does not match');
413420

414421
selectedTab.ionSelect.emit(selectedTab);
415422
this.ionChange.emit(selectedTab);
416423
}
417424

418425
_tabSwitchEnd(selectedTab: Tab, selectedPage: ViewController, currentPage: ViewController) {
426+
assert(selectedTab, 'selectedTab must be valid');
427+
assert(this._tabs.indexOf(selectedTab) >= 0, 'selectedTab must be one of the tabs');
428+
419429
// Update tabs selection state
420430
const tabs = this._tabs;
421431
let tab: Tab;
@@ -473,9 +483,10 @@ export class Tabs extends Ion implements AfterViewInit {
473483
* @return {Tab} Returns the currently selected tab
474484
*/
475485
getSelected(): Tab {
476-
for (var i = 0; i < this._tabs.length; i++) {
477-
if (this._tabs[i].isSelected) {
478-
return this._tabs[i];
486+
const tabs = this._tabs;
487+
for (var i = 0; i < tabs.length; i++) {
488+
if (tabs[i].isSelected) {
489+
return tabs[i];
479490
}
480491
}
481492
return null;

0 commit comments

Comments
 (0)