Skip to content

fix(tabs, tab-bar): use standalone tab bar in Vue #29925

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

Merged
merged 3 commits into from
Oct 11, 2024
Merged

Conversation

thetaPC
Copy link
Contributor

@thetaPC thetaPC commented Oct 7, 2024

Issue number: resolves part of #29885


What is the current behavior?

Vue: Tab bar could be a standalone element within ion-tabs and would navigate without issues with a router outlet before v8.3:

<ion-tabs>
  <ion-router-outlet></ion-router-outlet>

  <TabBar></TabBar>
</ion-tabs>

It would work as if it was written as:

<ion-tabs>
  <ion-router-outlet></ion-router-outlet>

  <ion-tab-bar slot="bottom">
    <!-- Buttons -->
  </ion-tab-bar>
</ion-tabs>

After v8.3, any ion-tab-bar that was not a direct child of ion-tabs would lose it's expected behavior when used with a router outlet. If a user clicked on a tab button, then the content would not be redirected to that expected view.

What is the new behavior?

The Vue tab bar's _hasRouterOutlet prop has been modified to accept both Boolean and undefined values. When the value is undefined, it indicates that the ion-tab-bar component was not found within the slotted content of ion-tabs. This typically occurs when the tab bar is not passed as a direct child of ion-tabs.

In such cases, the tab bar will perform its own check to determine if an ion-router-outlet is present. This check cannot be handled by tabs, as it would need to wait until after mounting to access the DOM, which would be too late since the tab bar would have already executed the logic that depends on _hasRouterOutlet.

Does this introduce a breaking change?

  • Yes
  • No

Other information

Dev build: 8.3.3-dev.11728341918.1d3d4b3f

How to test:

  1. Clone the issue repro
  2. Navigate to folder 8.3.0-standalone
  3. Install deps
  4. Start app
  5. Click on the tab buttons
  6. Notice the content and URL doesn't change
  7. Install dev build: npm install @ionic/vue@8.3.3-dev.11728341918.1d3d4b3f
  8. Start app
  9. Click on the tab buttons
  10. Verify that the correct content and URL displays

Copy link

vercel bot commented Oct 7, 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 Oct 10, 2024 8:40pm

@github-actions github-actions bot added the package: vue @ionic/vue package label Oct 7, 2024
@thetaPC thetaPC marked this pull request as ready for review October 7, 2024 23:16
@thetaPC thetaPC requested a review from a team as a code owner October 7, 2024 23:16
@thetaPC thetaPC requested a review from BenOsodrac October 7, 2024 23:16
@thetaPC thetaPC requested a review from tanner-reits October 8, 2024 17:46
@manhtruongwang
Copy link

Do this also fix react version?

@thetaPC
Copy link
Contributor Author

thetaPC commented Oct 8, 2024

Hello @manhtruongwang! This PR only addresses the issue for Vue. A separate PR will be created for React.

@thetaPC thetaPC changed the title fix(tab-bar): use as standalone in vue fix(tab-bar): use as standalone in Vue Oct 9, 2024
Copy link
Contributor

@tanner-reits tanner-reits left a comment

Choose a reason for hiding this comment

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

LGTM, confirmed it fixes the issue repro

@thetaPC thetaPC changed the base branch from main to tabs-router-fixes October 10, 2024 15:06
@thetaPC thetaPC changed the title fix(tab-bar): use as standalone in Vue fix(tabs, tab-bar): use as standalone in Vue Oct 10, 2024
@thetaPC thetaPC changed the title fix(tabs, tab-bar): use as standalone in Vue fix(tabs, tab-bar): use standalone tab bar in Vue Oct 10, 2024
Copy link
Contributor

@tanner-reits tanner-reits left a comment

Choose a reason for hiding this comment

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

Don't have a lot of Vue experience, but provide/inject seems like a good approach. Confirmed this fixes the standalone reproduction and that the router outlet approach still works as well. Nice work 👍

@thetaPC thetaPC merged commit 3b01cdc into tabs-router-fixes Oct 11, 2024
46 checks passed
@thetaPC thetaPC deleted the ROU-11263 branch October 11, 2024 15:05
github-merge-queue bot pushed a commit that referenced this pull request Oct 16, 2024
Issue number: resolves #29885, resolves #29924

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

React and Vue:

Tab bar could be a standalone element within `IonTabs` and would
navigate without issues with a router outlet before v8.3:

```tsx
<IonTabs>
  <IonRouterOutlet></IonRouterOutlet>

  <IonTabBar></IonTabBar>
</IonTabs>
```

It would work as if it was written as:

```tsx
<IonTabs>
  <IonRouterOutlet></IonRouterOutlet>

  <IonTabBar slot="bottom">
    <!-- Buttons -->
  </IonTabBar>
</IonTabs>
```

After v8.3, any `ion-tab-bar` that was not a direct child of `ion-tabs`
would lose it's expected behavior when used with a router outlet. If a
user clicked on a tab button, then the content would not be redirected
to that expected view.

React only:

Users can no longer add a `ref` to the `IonRouterOutlet`, it always
returns undefined.

```
<IonTabs>
      <IonRouterOutlet ref={ref}>

     <IonTabBar slot="bottom">
    <!-- Buttons -->
  </IonTabBar>
</IonTabs>
```

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

The fixes were already reviewed through PR
#29925 and PR
#29927. I split them
to make it easier to review.

React and Vue:

The React tabs has been updated to pass data to the tab bar through
context instead of passing it through a ref. By using a context, the
data will be available for the tab bar to use regardless of its level.

React only:

Reverted the logic for `routerOutletRef` and added a comment of the
importance of it.

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!--
  If this introduces a breaking change:
1. Describe the impact and migration path for existing applications
below.
  2. Update the BREAKING.md file with the breaking change.
3. Add "BREAKING CHANGE: [...]" to the commit description when merging.
See
https://github.com/ionic-team/ionic-framework/blob/main/docs/CONTRIBUTING.md#footer
for more information.
-->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->

N/A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: vue @ionic/vue package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants