bug: react, IonTabBar does not allow for wrapped IonTabButton components
See original GitHub issueBug Report: Importing outer IonTabButton into IonTabBar does not render in React.
Ionic version: [x] 5.x (React)
Current behavior: I am following the docs on creating the tabbar with tab buttons which works perfectly:
const Tabs = () => {
return (
<IonReactRouter>
<IonTabs>
<IonRouterOutlet>
<Routes />
</IonRouterOutlet>
<IonTabBar slot="bottom">
<IonTabButton tab="settings" href="/settings">
<IonIcon icon={cog} />
<IonLabel>Settings</IonLabel>
</IonTabButton>
<IonTabButton tab="Login" href="/login">
<IonIcon icon={triangle} />
<IonLabel>Login / Register</IonLabel>
</IonTabButton>
</IonTabBar>
</IonTabs>
</IonReactRouter>
)
}
Renders like it is supposed to:
I particularly like breaking down components a bit more, so let’s start with just one file:
// SettingsTab.tsx
import { IonIcon, IonLabel, IonTabButton } from "@ionic/react"
import { cog } from "ionicons/icons"
export const SettingsTab = () => (
<IonTabButton tab="settings" href="/settings">
<IonIcon icon={cog} />
<IonLabel>Settings</IonLabel>
</IonTabButton>
)
And import it and use it on my Tabs.tsx:
const Tabs = () => {
return (
<IonReactRouter>
<IonTabs>
<IonRouterOutlet>
<Routes />
</IonRouterOutlet>
<IonTabBar slot="bottom">
<SettingsTab />
<IonTabButton tab="Login" href="/login">
<IonIcon icon={triangle} />
<IonLabel>Login / Register</IonLabel>
</IonTabButton>
</IonTabBar>
</IonTabs>
</IonReactRouter>
)
}
Expected behaviour:
Now I would expect the behaviour to be the same as the previous one when I declared all buttons directly inside the Tabs, but this is what I am getting instead:
Steps to reproduce:
- Install the latest Ionic React
- Start a Tabs application
- Create a new component that exports a single tab button, for example:
export const SettingsTab = () => ( <IonTabButton tab="settings" href="/settings"> <IonIcon icon={cog} /> <IonLabel>Settings</IonLabel> </IonTabButton> )
- import that component into the tabs and place it within
<IonTabBar></IonTabBar>
Thanks
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:8 (1 by maintainers)
Top Results From Across the Web
React + Ionic 5: Tab navigation problems - Stack Overflow
According to the React Tabs starter template you have to nest the IonRouterOutlet inside of IonTabs , which is nested in IonReactRouter ....
Read more >Problem with tabs and shared ion-menu - Ionic Vue
I've added the same menu to each tab using ion-split-pane but when I navigate between tabs, I get an error, Cannot read property...
Read more >Material Top Tabs Navigator | React Navigation
A material-design themed tab bar on the top of the screen that lets you switch between different routes by tapping the tabs or...
Read more >Styling ion-tabs in Ionic 5 - DEV Community
This web component is smart enough to manage different stack ... <ion-tabs> <ion-tab-bar slot="bottom"> <ion-tab-button tab="home" ...
Read more >ionic Archives - LogRocket Blog
Ionic doesn't use native platform-specific UI elements. ... The above command triggers a React production build and won't enable the hot-reloading (HMR) ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks, I can reproduce this issue. The problem is that when
IonTabBar
renders its child components, it filters out anything that is notIonTabButton
: https://github.com/ionic-team/ionic-framework/blob/master/packages/react/src/components/navigation/IonTabBar.tsx#L221Facing the same issue at the moment. Does anybody know of a workaround?