Skip to content
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

fix(tabs, tab-bar): use standalone tab bar in React #29927

Merged
merged 5 commits into from
Oct 15, 2024

Conversation

thetaPC
Copy link
Contributor

@thetaPC thetaPC commented Oct 9, 2024

Issue number: resolves part of #29885, resolves #29924


What is the current behavior?

React: There are two issues here.

Issue 1:

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

<IonTabs>
  <IonRouterOutlet></IonRouterOutlet>

  <IonTabBar></IonTabBar>
</IonTabs>

It would work as if it was written as:

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

Issue 2:

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?

Issue 1:

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.

Issue 2:

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

Does this introduce a breaking change?

  • Yes
  • No

Other information

Dev build: 8.3.3-dev.11728581904.17739cf7

How to test Issue 1:

  1. Create a new React Ionic Framework app (recommended to use Tabs starter)
  2. Install deps
  3. Move the IonTabBar into a separate component
  4. Use the new component that holds IonTabBar
  5. Run project
  6. Click on any of the tab buttons
  7. Notice that the content and URL does not update
  8. Install dev build: npm install @ionic/react@8.3.3-dev.11728581904.17739cf7
  9. Run project
  10. Click on any of the tab buttons
  11. Verify that the content and URL updates correctly

How to test Issue 2:

  1. Clone the issue repo (second link at the top)
  2. Install deps
  3. Run project
  4. Open the browser console
  5. Notice that it displays an undefined
  6. Install the dev build: npm install @ionic/react@8.3.3-dev.11728581904.17739cf7
  7. Run project
  8. Verify that the console log now displays ion-router-outlet

Copy link

vercel bot commented Oct 9, 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 5:34pm

@thetaPC thetaPC changed the base branch from main to tabs-router-fixes October 10, 2024 15:05
@thetaPC thetaPC marked this pull request as ready for review October 10, 2024 17:48
@thetaPC thetaPC requested a review from a team as a code owner October 10, 2024 17:48
@thetaPC thetaPC requested review from gnbm and BenOsodrac and removed request for a team October 10, 2024 17:48
@thetaPC thetaPC changed the title fix(react): use as standalone in React fix(tabs, tab-bar): use as standalone in React Oct 10, 2024
@thetaPC thetaPC changed the title fix(tabs, tab-bar): use as standalone in React fix(tabs, tab-bar): use standalone tab bar in React Oct 10, 2024
if (React.isValidElement(child)) {
const isRouterOutlet =
child.type === IonRouterOutlet ||
(child.type as any).isRouterOutlet ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Just an observation, but maybe in these cases is better to use unknown than any

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll keep that in mind. I recall that we have a ticket to improve the types for this so we can make the update then. Thank you!

@thetaPC thetaPC requested a review from brandyscarney October 11, 2024 15:06
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.

Both test cases pass. 👍

@thetaPC thetaPC merged commit a54a934 into tabs-router-fixes Oct 15, 2024
71 checks passed
@thetaPC thetaPC deleted the ROU-11271 branch October 15, 2024 23:20
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: react @ionic/react package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants