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

feat(angular): use tabs without router #29786

Merged
merged 20 commits into from
Aug 23, 2024
Merged

feat(angular): use tabs without router #29786

merged 20 commits into from
Aug 23, 2024

Conversation

thetaPC
Copy link
Contributor

@thetaPC thetaPC commented Aug 20, 2024

Issue number: part of #25184

This PR does not completely close the issue since it only addresses the Angular portion. The other frameworks will be done through other PRs.


What is the current behavior?

Angular: Developers are defaulted to have ion-router-outlet when ion-tabs is in their app. 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.
  • 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.11724363936.1f6132ca

Copy link

vercel bot commented Aug 20, 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:50pm

@thetaPC thetaPC marked this pull request as ready for review August 21, 2024 16:32
@thetaPC thetaPC requested a review from a team as a code owner August 21, 2024 16:32
@thetaPC thetaPC requested review from rugoncalves and brandyscarney and removed request for a team August 21, 2024 16:33
@@ -39,8 +41,29 @@ export abstract class IonTabs implements AfterContentInit, AfterContentChecked {

private tabBarSlot = 'bottom';

private hasTab = false;
private selectedTab?: any;
Copy link
Contributor

Choose a reason for hiding this comment

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

Using any here is overriding the type signature of treating it as optionally defined (undefined). This means you are missing out on potential errors on L203, L206 and L212.

I would recommend minimally updating the type signature to:

private selectedTab?: { tab: string };

and then handling those type errors that arise for the selectedTab not being defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

}

if (leavingTab?.tab !== selectedTab.tab) {
if (leavingTab) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this should be checking that the el is defined, not the leavingTab, since it will based on the check on L206.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

}

private tabSwitch(): void {
const selectedTab = this.selectedTab;
Copy link
Contributor

Choose a reason for hiding this comment

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

~ These two lines could be minimized to:

const { selectedTab, leavingTab } = this;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

packages/angular/common/src/directives/navigation/tabs.ts Outdated Show resolved Hide resolved
@@ -11,11 +11,13 @@ import { IonRouterOutlet } from './ion-router-outlet';
<ng-content select="[slot=top]"></ng-content>
<div class="tabs-inner" #tabsInner>
<ion-router-outlet
*ngIf="tabs?.length === 0"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can tabs be undefined? The type signature implies not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After reviewing it further, it seems that there isn't a moment that it would be undefined. No issues were found when removing the optional chain. f6132ca

@@ -11,11 +12,13 @@ import { IonRouterOutlet } from './router-outlet';
<ng-content select="[slot=top]"></ng-content>
<div class="tabs-inner" #tabsInner>
<ion-router-outlet
*ngIf="tabs?.length === 0"
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar feedback here if tabs can be undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

packages/angular/test/base/e2e/src/standalone/tabs.spec.ts Outdated Show resolved Hide resolved
/**
* Note: These must be redeclared on each child class since it needs
* access to generated components such as IonRouterOutlet and IonTabBar.
*/
abstract outlet: any;
abstract tabBar: any;
abstract tabBars: any;
abstract tabs: any;
Copy link
Contributor

Choose a reason for hiding this comment

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

Minimally the type signature should be:

abstract tabs: QueryList<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.

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 Angular tabs starter app (NgModule)
  • A new Angular tabs starter app (Standalone)
  • A new Angular tabs starter app with ion-router-outlet removed and <ion-tab> components added containing only text content (NgModule)
  • A new Angular tabs starter app with ion-router-outlet removed and <ion-tab> components added containing only text content (Standalone)
  • The Ionic Angular Conference App

Everything is working correctly. Great job on this! 🎉

@thetaPC thetaPC merged commit 50ba143 into tabs-router Aug 23, 2024
57 checks passed
@thetaPC thetaPC deleted the ROU-11003 branch August 23, 2024 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: angular @ionic/angular package package: core @ionic/core package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants