question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: react, IonTabBar does not allow for wrapped IonTabButton components

See original GitHub issue

Bug 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:

Screenshot 2021-03-22 at 22 20 35

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: Screenshot 2021-03-22 at 22 25 15

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:open
  • Created 2 years ago
  • Reactions:2
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
liamdebeasicommented, Mar 24, 2021

Thanks, I can reproduce this issue. The problem is that when IonTabBar renders its child components, it filters out anything that is not IonTabButton: https://github.com/ionic-team/ionic-framework/blob/master/packages/react/src/components/navigation/IonTabBar.tsx#L221

0reactions
aleksei-trocommented, Jun 9, 2022

Facing the same issue at the moment. Does anybody know of a workaround?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found