Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions packages/react/src/components/navigation/IonTabBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,20 @@ class IonTabBarUnwrapped extends React.PureComponent<InternalProps, IonTabBarSta
this.context.resetTab(e.detail.tab, originalHref, tappedTab.originalRouteOptions);
}
} else {
if (this.props.onIonTabsWillChange) {
this.props.onIonTabsWillChange(new CustomEvent('ionTabWillChange', { detail: { tab: e.detail.tab } }));
let onWillChange = this.props.onIonTabsWillChange;
let onDidChange = this.props.onIonTabsDidChange;
if (this.props.tabsContext) {
Comment thread
ShaneK marked this conversation as resolved.
Comment thread
ShaneK marked this conversation as resolved.
onWillChange = this.props.tabsContext?.tabBarProps.onIonTabsWillChange ?? this.props.onIonTabsWillChange;
onDidChange = this.props.tabsContext?.tabBarProps.onIonTabsDidChange ?? this.props.onIonTabsDidChange;
}
if (this.props.onIonTabsDidChange) {
this.props.onIonTabsDidChange(new CustomEvent('ionTabDidChange', { detail: { tab: e.detail.tab } }));

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

if (hasRouterOutlet) {
this.setActiveTabOnContext(e.detail.tab);
this.context.changeTab(e.detail.tab, currentHref, e.detail.routeOptions);
Expand Down
15 changes: 13 additions & 2 deletions packages/react/test/base/tests/e2e/specs/tabs/tabs.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ describe('IonTabs', () => {
/**
* Verifies that tabs with similar route prefixes (e.g., /home, /home2, /home3)
* correctly select the matching tab instead of the first prefix match.
*
*
* @see https://github.com/ionic-team/ionic-framework/issues/30448
*/
describe('Similar Route Prefixes', () => {
Expand Down Expand Up @@ -58,7 +58,11 @@ describe('IonTabs', () => {

describe('Without IonRouterOutlet', () => {
beforeEach(() => {
cy.visit('/tabs-basic');
cy.visit('/tabs-basic', {
onBeforeLoad(win) {
cy.spy(win.console, 'log').as('consoleLog');
},
});
});

it.skip('should show correct tab when clicking the tab button', () => {
Expand All @@ -83,5 +87,12 @@ describe('IonTabs', () => {

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

it('should fire tab change events on tab click', () => {
cy.get('ion-tab-button[tab="tab2"]').click();

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