Skip to content

chore(tabs): use custom portal template directive for hosting tab body content #7266

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 1 commit into from
Nov 10, 2017

Conversation

josephperrott
Copy link
Member

@josephperrott josephperrott commented Sep 22, 2017

Related to #6832
By moving the entrance logic into the MdTabBodyPortal setting up the content after change detection is avoided.

Fixes #7032 #7061

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Sep 22, 2017
@josephperrott josephperrott force-pushed the tabs branch 2 times, most recently from 2ce1567 to f552539 Compare September 22, 2017 20:35

/** Event emitted when the tab begins to animate towards the center as the active tab. */
@Output() onCentering: EventEmitter<number> = new EventEmitter<number>();

/** Event emitted when the tab completes its animation away from the center. */
@Output() afterLeavingCenter: EventEmitter<number> = new EventEmitter<number>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we prefix this w/ a underscore since its private ... so _afterLeavingCenter?

Whats the number type used for?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, and the number was the result of a copy paste from the emitter above. Since I wasn't using the result at all I didn't notice.

@josephperrott josephperrott added P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful pr: needs review labels Sep 22, 2017
@josephperrott
Copy link
Member Author

@andrewseguin If you have a moment to take a look. :D

fixture.componentInstance.position = 1;
fixture.detectChanges();
tick(1000);
Copy link
Contributor

Choose a reason for hiding this comment

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

Leave comment explaining where 1000 came from and why tick was needed

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

export class MdTabBodyPortal extends _MdTabBodyPortalBaseClass implements OnInit {
/** Whether the tab body should be visible. */
visible = false;
/** A subscription to events for when the tab body begins centering. */
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the subs should be private (preceeded with an underscore)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

constructor(
_componentFactoryResolver: ComponentFactoryResolver,
_viewContainerRef: ViewContainerRef,
private host: MdTabBody) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add underscore to host to show its private

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

/** Set up subscriptions for changing visibility and set initial visibility. */
ngOnInit(): void {
this.centeringSub = this.host.onCentering.subscribe(() => this.setVisibility(true));
this.leavingCenterSub = this.host._afterLeavingCenter.subscribe(
Copy link
Contributor

Choose a reason for hiding this comment

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

this.leavingCenterSub = 
    this.host._afterLeavingCenter.subscribe(() => this.setVisibility(false));

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

expect(getSelectedLabel(fixture).textContent).toMatch('Junk food');
expect(getSelectedContent(fixture).textContent).toMatch('Pizza, fries');

tabGroup.selectedIndex = 2;
fixture.detectChanges();
fixture.whenStable().then(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add comment why whenStable is needed

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@@ -0,0 +1,44 @@
import {Component} from '@angular/core';
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why the extra test is needed, isn't this covered by tab-group.spec.ts?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was not caught by the current tests in tab-group.spec.ts, would you prefer I move it into tab-group.spec.ts?

@@ -175,7 +220,7 @@ export class MdTabBody implements OnInit, AfterViewChecked {
}

/** Whether the provided position state is considered center, regardless of origin. */
private _isCenterPosition(position: MdTabBodyPositionState|string): boolean {
_isCenterPosition(position: MdTabBodyPositionState|string): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

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

Will need to remove the underscore if it's not private.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ack.

Copy link
Contributor

@andrewseguin andrewseguin left a comment

Choose a reason for hiding this comment

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

LGTM - nice work, takes a lot to get a good hold of all the change detection pieces happening in the tabs component

@andrewseguin
Copy link
Contributor

Add merge_ready after you move the test to tab-group.spec.ts

constructor(
_componentFactoryResolver: ComponentFactoryResolver,
_viewContainerRef: ViewContainerRef,
private _host: MdTabBody) {
Copy link
Contributor

@mmalerba mmalerba Sep 25, 2017

Choose a reason for hiding this comment

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

@josephperrott it looks like we need to use a forwardRef here since this directive is used in the template for MdTabBody. Here's an example for a similar situation in the sidenav: https://github.com/angular/material2/blob/master/src/lib/sidenav/sidenav.ts#L36

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@mmalerba mmalerba removed the action: merge The PR is ready for merge by the caretaker label Sep 25, 2017
@josephperrott josephperrott force-pushed the tabs branch 2 times, most recently from 4dfdf85 to d587250 Compare September 25, 2017 15:32
@mmalerba mmalerba added the action: merge The PR is ready for merge by the caretaker label Sep 25, 2017
@mmalerba
Copy link
Contributor

@josephperrott This seems to break tab animations in some cases. Go to tabs demo page under "Tab Group Demo - Dynamic Tabs" and click "Tab 4" to see the broken behavior

@mmalerba mmalerba removed the action: merge The PR is ready for merge by the caretaker label Sep 26, 2017
@josephperrott
Copy link
Member Author

@mmalerba Issue resolved.

@josephperrott josephperrott added the action: merge The PR is ready for merge by the caretaker label Sep 28, 2017
@amcdnl
Copy link
Contributor

amcdnl commented Oct 3, 2017

@josephperrott - Can you rebase?

@kara kara added the presubmit failures This PR has failures in Google's internal presubmit process and cannot be immediately merged label Oct 3, 2017
@josephperrott josephperrott force-pushed the tabs branch 2 times, most recently from 2a8a5e8 to b894fe8 Compare October 4, 2017 18:06
@jelbourn jelbourn added P2 The issue is important to a large percentage of users, with a workaround and removed P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful labels Oct 24, 2017
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement P2 The issue is important to a large percentage of users, with a workaround presubmit failures This PR has failures in Google's internal presubmit process and cannot be immediately merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Fast tab switch forces scroll up
7 participants