Skip to content

fix(angular): tabs supports conditional slot bindings - #27582

Merged
sean-perkins merged 6 commits into
feature-7.1from
FW-4121
Jun 7, 2023
Merged

sean-perkins merged 6 commits into
feature-7.1from
FW-4121

Conversation

@sean-perkins

@sean-perkins sean-perkins commented Jun 1, 2023 •

Copy link
Copy Markdown
Contributor

Issue number: Resolves #19484


What is the current behavior?

The Angular implementation of ion-tabs does not support conditional binding the slot property on ion-tab-bar or assigning a variable as the slot.

For example, this usage is invalid:

<ion-tabs>
  <ion-tab-bar [slot]="slot"></ion-tab-bar>
</ion-tabs>

This occurs because ng-content only supports static content projection. It is not intended for scenarios where the content can be relocated or conditionally rendered.

An example of static content projection would be:

<ion-tabs>
  <ion-tab-bar slot="top"></ion-tab-bar>
</ion-tabs>

What is the new behavior?

  • ion-tabs supports conditional slot bindings or a slot that is bound to a variable in Angular.

The revised implementation relocates the tab bar in the ion-tabs template, based on it's current slot attribute. The implementation checks the tab bar slot whenever the content changes.

Does this introduce a breaking change?

  • Yes
  • No

Other information

Dev-build: 7.0.11-dev.11685631370.18980633

@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@github-actions github-actions Bot added the package: angular @ionic/angular package label Jun 1, 2023
* Relocates the tab bar to the new slot position.
*/
private relocateTabBar(): void {
const tabBar = (this.tabBar as any).el as HTMLElement;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We have options here regarding the any type (and the any on L175). Our automatic generated proxies have the el property as protected. To make the types valid, we would need to disable automatically generating the proxy and manually wrap it with a public field member.

I don't think the effort of maintaining the proxy is worth the type efficiency here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That makes sense. It might be a good idea to include a comment for the reasoning to keep it as type any.

@sean-perkins

Copy link
Copy Markdown
Contributor Author

Thoughts on targeting this to feature-7.1 instead of main? While CI passes and I experimented locally, I have a small concern that someone is doing some weird content projection/rendering that may not work as intended with this logic. Targeting a minor would minimize this risk.

@sean-perkins
sean-perkins marked this pull request as ready for review June 1, 2023 15:23
@sean-perkins
sean-perkins requested review from a team, brandyscarney and thetaPC and removed request for a team and brandyscarney June 1, 2023 15:24
@thetaPC

thetaPC commented Jun 1, 2023

Copy link
Copy Markdown
Contributor

Thoughts on targeting this to feature-7.1 instead of main? While CI passes and I experimented locally, I have a small concern that someone is doing some weird content projection/rendering that may not work as intended with this logic. Targeting a minor would minimize this risk.

I agree to target this to feature-7.1. There might be more edge cases that might happen down the line.

@sean-perkins
sean-perkins changed the base branch from main to feature-7.1 June 1, 2023 16:05
@sean-perkins

Copy link
Copy Markdown
Contributor Author

Sounds good 👍 I'll get feature-7.1 up-to-date with main and then rebase so the diff is only the few files.

@thetaPC thetaPC left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, tested the build on the tabs starter.

* Relocates the tab bar to the new slot position.
*/
private relocateTabBar(): void {
const tabBar = (this.tabBar as any).el as HTMLElement;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That makes sense. It might be a good idea to include a comment for the reasoning to keep it as type any.

@liamdebeasi liamdebeasi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tested locally and it works great. Nice job!

@sean-perkins
sean-perkins merged commit d20bea5 into feature-7.1 Jun 7, 2023
@sean-perkins
sean-perkins deleted the FW-4121 branch June 7, 2023 02:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: angular @ionic/angular package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: ion-tab-bar slot not working with Angular binding

3 participants