-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Conversation
2ce1567
to
f552539
Compare
src/lib/tabs/tab-body.ts
Outdated
|
||
/** 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>(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
@andrewseguin If you have a moment to take a look. :D |
src/lib/tabs/tab-body.spec.ts
Outdated
fixture.componentInstance.position = 1; | ||
fixture.detectChanges(); | ||
tick(1000); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/lib/tabs/tab-body.ts
Outdated
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. */ |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/lib/tabs/tab-body.ts
Outdated
constructor( | ||
_componentFactoryResolver: ComponentFactoryResolver, | ||
_viewContainerRef: ViewContainerRef, | ||
private host: MdTabBody) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/lib/tabs/tab-body.ts
Outdated
/** 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( |
There was a problem hiding this comment.
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));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/lib/tabs/tab-group.spec.ts
Outdated
expect(getSelectedLabel(fixture).textContent).toMatch('Junk food'); | ||
expect(getSelectedContent(fixture).textContent).toMatch('Pizza, fries'); | ||
|
||
tabGroup.selectedIndex = 2; | ||
fixture.detectChanges(); | ||
fixture.whenStable().then(() => { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/lib/tabs/tabs.spec.ts
Outdated
@@ -0,0 +1,44 @@ | |||
import {Component} from '@angular/core'; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
?
src/lib/tabs/tab-body.ts
Outdated
@@ -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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack.
There was a problem hiding this 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
Add |
src/lib/tabs/tab-body.ts
Outdated
constructor( | ||
_componentFactoryResolver: ComponentFactoryResolver, | ||
_viewContainerRef: ViewContainerRef, | ||
private _host: MdTabBody) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
4dfdf85
to
d587250
Compare
@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 Issue resolved. |
@josephperrott - Can you rebase? |
2a8a5e8
to
b894fe8
Compare
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Related to #6832
By moving the entrance logic into the
MdTabBodyPortal
setting up the content after change detection is avoided.Fixes #7032 #7061