-
Notifications
You must be signed in to change notification settings - Fork 13.4k
feat(vue): use tabs without router #29775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
| import { IonicVue, IonRouterOutlet, IonPage, IonTabs, IonTabBar } from '@ionic/vue'; | ||
|
|
||
| describe('ion-tab-bar', () => { | ||
| it('should render in the top slot', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the tests since we are using defineCustomElement in IonTabs,
- the slots are now being rendered within the shadow DOM and the tests don't have access to that
- the rendering of the slots are based on the core components which is already being tested there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found a few issues testing without a router. Steps to create the test app:
- Create a new Ionic Vue tabs app:
ionic start myVueTabsApp tabs --type=vue - Navigate to the app directory:
cd ./myVueTabsApp - Install the dev build:
npm i @ionic/vue@8.2.8-dev.11724095971.1e1b89ef @ionic/vue-router@8.2.8-dev.11724095971.1e1b89ef - Serve the app:
ionic serve - Navigate to http://localhost:8100/ in the browser
Issue 1 - Undefined tab
- Update
src/App.vueto the following:<template> <ion-app> <ion-tabs> <ion-tab tab="tab1"> <ion-content>Tab 1</ion-content> </ion-tab> <ion-tab tab="tab2"> <ion-content>Tab 2</ion-content> </ion-tab> <ion-tab-bar slot="bottom"> <ion-tab-button tab="tab1"> <ion-icon :icon="triangle"></ion-icon> <ion-label>Tab 1</ion-label> </ion-tab-button> <ion-tab-button tab="tab2"> <ion-icon :icon="ellipse"></ion-icon> <ion-label>Tab 2</ion-label> </ion-tab-button> <ion-tab-button tab="tab3"> <ion-icon :icon="square"></ion-icon> <ion-label>Tab 3</ion-label> </ion-tab-button> </ion-tab-bar> </ion-tabs> </ion-app> </template> <script lang="ts"> import { IonApp, IonContent, IonLabel, IonIcon, IonTabs, IonTab, IonTabBar, IonTabButton } from '@ionic/vue'; import { ellipse, square, triangle } from 'ionicons/icons'; import { defineComponent } from 'vue'; export default defineComponent({ components: { IonApp, IonContent, IonLabel, IonIcon, IonTab, IonTabs, IonTabBar, IonTabButton }, setup() { return { ellipse, square, triangle }; }, }); </script>
- Refresh the browser
- Click on "Tab 3"
- Open the console and see error:
tab with id: "undefined" does not exist - Compare this to a Vue tabs starter using router with a missing path for
tab3and it gives a warning:[Vue Router warn]: No match found for location with path "/tabs/tab3" - Removing the
hreffrom the 3rd<ion-tab-button>in the app with a router results in no warnings or errors in the console.
Issue 2 - Selected tab with href
- Update
src/App.vueto the following:<template> <ion-app> <ion-tabs> <ion-tab tab="tab1"> <ion-content>Tab 1</ion-content> </ion-tab> <ion-tab tab="tab2"> <ion-content>Tab 2</ion-content> </ion-tab> <ion-tab tab="tab3"> <ion-content>Tab 3</ion-content> </ion-tab> <ion-tab-bar slot="bottom"> <ion-tab-button tab="tab1" href="/tabs/tab1"> <ion-icon :icon="triangle"></ion-icon> <ion-label>Tab 1</ion-label> </ion-tab-button> <ion-tab-button tab="tab2" href="/tabs/tab2"> <ion-icon :icon="ellipse"></ion-icon> <ion-label>Tab 2</ion-label> </ion-tab-button> <ion-tab-button tab="tab3" href="/tabs/tab3"> <ion-icon :icon="square"></ion-icon> <ion-label>Tab 3</ion-label> </ion-tab-button> </ion-tab-bar> </ion-tabs> </ion-app> </template> <script lang="ts"> import { IonApp, IonContent, IonLabel, IonIcon, IonTabs, IonTab, IonTabBar, IonTabButton } from '@ionic/vue'; import { ellipse, square, triangle } from 'ionicons/icons'; import { defineComponent } from 'vue'; export default defineComponent({ components: { IonApp, IonContent, IonLabel, IonIcon, IonTab, IonTabs, IonTabBar, IonTabButton }, setup() { return { ellipse, square, triangle }; }, }); </script>
- Refresh the browser
- Click on the 3rd tab "Tab 3"
- See that it switches to the 3rd tab correctly
- Refresh the browser
- See that "Tab 3" is still selected but the 1st tab "Tab 1" content is displayed
This is the same issue I reported when testing React without a router.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: Brandy Carney <brandyscarney@users.noreply.github.com>
brandyscarney
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested the latest dev build in:
- A new Vue tabs starter app
- A new Vue tabs starter app with
<ion-router-outlet>removed and<ion-tab>components containing only text content - The Ionic Vue Conference App
Everything is working correctly. Great job on this! 🎉
Co-authored-by: Brandy Carney <brandyscarney@users.noreply.github.com>
Issue number: part of #25184
This PR does not completely close the issue since it only addresses the Vue portion. The other frameworks will be done through other PRs.
What is the current behavior?
Vue: Developers have to provide
ion-router-outletto useion-tabs. This means that developers are forced to tie their tabs to a router.What is the new behavior?
ion-tabscan be used without a router outlet as long asion-tabis a child andion-router-outletis not./tabs-basicDoes this introduce a breaking change?
Developers who are still using
ion-tabswithion-router-outletwill not experience any changes. This feature PR introduces another option to useion-tabs, no changes for the current implementation.Other information
Dev build: 8.2.8-dev.11724361569.1dd52246