GitHub

File tree

  • packages/react

    • src/components/navigation

    • test/base/tests/e2e/specs/tabs

Original file line numberDiff line numberDiff line change

@@ -224,12 +224,20 @@ class IonTabBarUnwrapped extends React.PureComponent<InternalProps, IonTabBarSta

224224

this.context.resetTab(e.detail.tab, originalHref, tappedTab.originalRouteOptions);

225225

}

226226

} else {

227-

if (this.props.onIonTabsWillChange) {

228-

this.props.onIonTabsWillChange(new CustomEvent('ionTabWillChange', { detail: { tab: e.detail.tab } }));

227+

let onWillChange = this.props.onIonTabsWillChange;

228+

let onDidChange = this.props.onIonTabsDidChange;

229+

if (this.props.tabsContext) {

230+

onWillChange = this.props.tabsContext?.tabBarProps.onIonTabsWillChange ?? this.props.onIonTabsWillChange;

231+

onDidChange = this.props.tabsContext?.tabBarProps.onIonTabsDidChange ?? this.props.onIonTabsDidChange;

229232

}

230-

if (this.props.onIonTabsDidChange) {

231-

this.props.onIonTabsDidChange(new CustomEvent('ionTabDidChange', { detail: { tab: e.detail.tab } }));

233+
234+

if (onWillChange) {

235+

onWillChange(new CustomEvent('ionTabWillChange', { detail: { tab: e.detail.tab } }));

236+

}

237+

if (onDidChange) {

238+

onDidChange(new CustomEvent('ionTabDidChange', { detail: { tab: e.detail.tab } }));

232239

}

240+
233241

if (hasRouterOutlet) {

234242

this.setActiveTabOnContext(e.detail.tab);

235243

this.context.changeTab(e.detail.tab, currentHref, e.detail.routeOptions);

Original file line numberDiff line numberDiff line change

@@ -2,7 +2,7 @@ describe('IonTabs', () => {

22

/**

33

* Verifies that tabs with similar route prefixes (e.g., /home, /home2, /home3)

44

* correctly select the matching tab instead of the first prefix match.

5-

*

5+

*

66

* @see https://github.com/ionic-team/ionic-framework/issues/30448

77

*/

88

describe('Similar Route Prefixes', () => {

@@ -58,7 +58,11 @@ describe('IonTabs', () => {

5858
5959

describe('Without IonRouterOutlet', () => {

6060

beforeEach(() => {

61-

cy.visit('/tabs-basic');

61+

cy.visit('/tabs-basic', {

62+

onBeforeLoad(win) {

63+

cy.spy(win.console, 'log').as('consoleLog');

64+

},

65+

});

6266

});

6367
6468

it.skip('should show correct tab when clicking the tab button', () => {

@@ -83,5 +87,12 @@ describe('IonTabs', () => {

8387
8488

cy.url().should('include', '/tabs-basic');

8589

});

90+
91+

it('should fire tab change events on tab click', () => {

92+

cy.get('ion-tab-button[tab="tab2"]').click();

93+
94+

cy.get('@consoleLog').should('be.calledWith', 'onIonTabsWillChange', 'tab2');

95+

cy.get('@consoleLog').should('be.calledWith', 'onIonTabsDidChange:', 'tab2');

96+

});

8697

});

8798

});

Read the original on github.com ↗