fix(react): only pass tab event props from IonTabs to IonTabBar if defined (#23024)

resolves #23023
This commit is contained in:
Liam DeBeasi 2021-03-05 16:03:14 -05:00 committed by GitHub
parent de58238333
commit f94e618a7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 12 deletions

View File

@ -101,23 +101,39 @@ export class IonTabs extends React.Component<Props> {
} 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);
}
});