Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/vue/src/components/IonTabBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const IonTabBar = defineComponent({
tabs: {}
};
const currentInstance = getCurrentInstance();
const isTabButton = (child: any) => child.type?.name === 'IonTabButton';
/**
* For each tab, we need to keep track of its
* base href as well as any child page that
Expand All @@ -33,7 +34,7 @@ export const IonTabBar = defineComponent({
*/
const children = (currentInstance.subTree.children || []) as VNode[];
children.forEach((child: VNode) => {
if (child.type && (child.type as any).name === 'IonTabButton') {
if (isTabButton(child)) {
tabState.tabs[child.props.tab] = {
originalHref: child.props.href,
currentHref: child.props.href,
Expand Down Expand Up @@ -65,7 +66,7 @@ export const IonTabBar = defineComponent({
* it in the tabs state.
*/
childNodes.forEach((child: VNode) => {
if (child.type && (child.type as any).name === 'IonTabButton') {
if (isTabButton(child)) {
const tab = tabs[child.props.tab];
if (!tab || (tab.originalHref !== child.props.href)) {

Expand Down Expand Up @@ -106,7 +107,7 @@ export const IonTabBar = defineComponent({
}
}

const activeChild = childNodes.find((child: VNode) => child.props.tab === activeTab);
const activeChild = childNodes.find((child: VNode) => isTabButton(child) && child.props?.tab === activeTab);
const tabBar = this.$refs.ionTabBar;
const tabDidChange = activeTab !== prevActiveTab;
if (activeChild && tabBar) {
Expand Down
34 changes: 34 additions & 0 deletions packages/vue/test-app/tests/unit/tab-bar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,38 @@ describe('ion-tab-bar', () => {
const innerHTML = wrapper.find('ion-tabs').html();
expect(innerHTML).toContain(`<div class="tabs-inner" style="position: relative; flex: 1; contain: layout size style;"><ion-router-outlet tabs="true"></ion-router-outlet></div><ion-tab-bar></ion-tab-bar></ion-tabs>`)
});

// Verifies the fix for https://github.com/ionic-team/ionic-framework/issues/22642
it('should not fail on non tab button elements', async () => {
const Tabs = {
components: { IonPage, IonTabs, IonTabBar },
template: `
<ion-page>
<ion-tabs>
<ion-tab-bar>
<!-- my comment -->
</ion-tab-bar>
</ion-tabs>
</ion-page>
`,
}

const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes: [
{ path: '/', component: Tabs }
]
});

router.push('/');
await router.isReady();
const wrapper = mount(App, {
global: {
plugins: [router, IonicVue]
}
});

const innerHTML = wrapper.find('ion-tabs').html();
expect(innerHTML).toContain(`><ion-tab-bar><!-- my comment --></ion-tab-bar>`)
})
});