From f94e618a7b307b143eb39c061dc9e6b80e11f862 Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Fri, 5 Mar 2021 16:03:14 -0500 Subject: [PATCH] fix(react): only pass tab event props from IonTabs to IonTabBar if defined (#23024) resolves #23023 --- .../src/components/navigation/IonTabs.tsx | 40 +++++++++++++------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/packages/react/src/components/navigation/IonTabs.tsx b/packages/react/src/components/navigation/IonTabs.tsx index 3a20a115cb..d4771275c4 100644 --- a/packages/react/src/components/navigation/IonTabs.tsx +++ b/packages/react/src/components/navigation/IonTabs.tsx @@ -101,23 +101,39 @@ export class IonTabs extends React.Component { } else if (child.type === Fragment && child.props.children[0].type === IonRouterOutlet) { outlet = child.props.children[0]; } - if (child.type === IonTabBar || child.type.isTabBar) { - tabBar = React.cloneElement(child, { - onIonTabsDidChange, - onIonTabsWillChange, - ref: this.tabBarRef, - }); + let childProps: any = { + ref: this.tabBarRef + } + + /** + * Only pass these props + * down from IonTabs to IonTabBar + * if they are defined, otherwise + * if you have a handler set on + * IonTabBar it will be overridden. + */ + if (onIonTabsDidChange !== undefined) { + childProps = { + ...childProps, + onIonTabsDidChange + } + } + + if (onIonTabsWillChange !== undefined) { + childProps = { + ...childProps, + onIonTabsWillChange + } + } + + if (child.type === IonTabBar || child.type.isTabBar) { + tabBar = React.cloneElement(child, childProps); } else if ( child.type === Fragment && (child.props.children[1].type === IonTabBar || child.props.children[1].type.isTabBar) ) { - - tabBar = React.cloneElement(child.props.children[1], { - onIonTabsDidChange, - onIonTabsWillChange, - ref: this.tabBarRef, - }); + tabBar = React.cloneElement(child.props.children[1], childProps); } });