Skip to content

Conversation

@thetaPC
Copy link
Contributor

@thetaPC thetaPC commented Aug 15, 2024

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-outlet to use ion-tabs. This means that developers are forced to tie their tabs to a router.

What is the new behavior?

  • ion-tabs can be used without a router outlet as long as ion-tab is a child and ion-router-outlet is not.
  • Added a test.
  • Added a test page: /tabs-basic

Does this introduce a breaking change?

  • Yes
  • No

Developers who are still using ion-tabs with ion-router-outlet will not experience any changes. This feature PR introduces another option to use ion-tabs, no changes for the current implementation.

Other information

Dev build: 8.2.8-dev.11724361569.1dd52246

@vercel
Copy link

vercel bot commented Aug 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ionic-framework ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 22, 2024 9:10pm

@github-actions github-actions bot added package: core @ionic/core package package: vue @ionic/vue package labels Aug 15, 2024
import { IonicVue, IonRouterOutlet, IonPage, IonTabs, IonTabBar } from '@ionic/vue';

describe('ion-tab-bar', () => {
it('should render in the top slot', async () => {
Copy link
Contributor Author

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,

  1. the slots are now being rendered within the shadow DOM and the tests don't have access to that
  2. the rendering of the slots are based on the core components which is already being tested there

@thetaPC thetaPC marked this pull request as ready for review August 19, 2024 20:03
@thetaPC thetaPC requested a review from a team as a code owner August 19, 2024 20:03
@thetaPC thetaPC requested review from OS-giulianasilva and brandyscarney and removed request for a team August 19, 2024 20:03
Copy link
Member

@brandyscarney brandyscarney Aug 20, 2024

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:

  1. Create a new Ionic Vue tabs app: ionic start myVueTabsApp tabs --type=vue
  2. Navigate to the app directory: cd ./myVueTabsApp
  3. Install the dev build: npm i @ionic/vue@8.2.8-dev.11724095971.1e1b89ef @ionic/vue-router@8.2.8-dev.11724095971.1e1b89ef
  4. Serve the app: ionic serve
  5. Navigate to http://localhost:8100/ in the browser

Issue 1 - Undefined tab

  1. Update src/App.vue to 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>
  2. Refresh the browser
  3. Click on "Tab 3"
  4. Open the console and see error: tab with id: "undefined" does not exist
  5. Compare this to a Vue tabs starter using router with a missing path for tab3 and it gives a warning: [Vue Router warn]: No match found for location with path "/tabs/tab3"
  6. Removing the href from 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

  1. Update src/App.vue to 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>
  2. Refresh the browser
  3. Click on the 3rd tab "Tab 3"
  4. See that it switches to the 3rd tab correctly
  5. Refresh the browser
  6. 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue 1: cc67360

Issue 2: 531ae5d

Co-authored-by: Brandy Carney <brandyscarney@users.noreply.github.com>
Copy link
Member

@brandyscarney brandyscarney left a 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: core @ionic/core package package: vue @ionic/vue package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants