fix(react): IonTabButton will call custom onClick handlers (#25313)

Resolves #22511
This commit is contained in:
Sean Perkins
2022-05-19 12:19:34 -04:00
committed by GitHub
parent 51f3179bcc
commit 6034418b33
7 changed files with 64 additions and 4 deletions

View File

@ -24,6 +24,7 @@ import './theme/variables.css';
import Main from './pages/Main';
import OverlayHooks from './pages/overlay-hooks/OverlayHooks';
import OverlayComponents from './pages/overlay-components/OverlayComponents';
import Tabs from './pages/Tabs';
setupIonicReact();
@ -34,6 +35,7 @@ const App: React.FC = () => (
<Route path="/" component={Main} />
<Route path="/overlay-hooks" component={OverlayHooks} />
<Route path="/overlay-components" component={OverlayComponents} />
<Route path="/tabs" component={Tabs} />
</IonRouterOutlet>
</IonReactRouter>
</IonApp>

View File

@ -4,11 +4,10 @@ import {
IonHeader,
IonLabel,
IonPage,
IonTitle,
IonToolbar,
IonItem,
IonList
IonList,
} from '@ionic/react';
interface MainProps {}
@ -32,6 +31,11 @@ const Main: React.FC<MainProps> = () => {
<IonLabel>Overlay Components</IonLabel>
</IonItem>
</IonList>
<IonList>
<IonItem routerLink="/tabs">
<IonLabel>Tabs</IonLabel>
</IonItem>
</IonList>
</IonContent>
</IonPage>
);

View File

@ -0,0 +1,23 @@
import React from 'react';
import { IonLabel, IonRouterOutlet, IonTabBar, IonTabButton, IonTabs } from '@ionic/react';
import { Route, Redirect } from 'react-router';
interface TabsProps {}
const Tabs: React.FC<TabsProps> = () => {
return (
<IonTabs>
<IonRouterOutlet>
<Redirect from="/tabs" to="/tabs/tab1" exact />
<Route path="/tabs/tab1" render={() => <IonLabel>Tab 1</IonLabel>} />
</IonRouterOutlet>
<IonTabBar slot="bottom">
<IonTabButton tab="tab1" onClick={() => window.alert('Tab was clicked')}>
<IonLabel>Click Handler</IonLabel>
</IonTabButton>
</IonTabBar>
</IonTabs>
);
};
export default Tabs;