-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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): observing tab header label changes to recalculate width #2186
Conversation
e56f38f
to
6ed8bec
Compare
constructor(private elementRef: ElementRef) {} | ||
|
||
ngAfterViewInit() { | ||
this.observer = new MutationObserver(mutations => mutations.forEach(() => this.event.emit())); |
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.
Might be a good idea to clear out the mutation observer on destroy.
selector: '[cdk-observe-content]' | ||
}) | ||
export class MdMutationObserver { | ||
private observer: MutationObserver; |
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.
We prefix private members with underscore (_observer
)
export class MdMutationObserver { | ||
private observer: MutationObserver; | ||
|
||
@Output('cdk-observe-content') event = new EventEmitter(); |
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.
I think it should be EventEmitter<void>
|
||
@Output('cdk-observe-content') event = new EventEmitter(); | ||
|
||
constructor(private elementRef: ElementRef) {} |
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.
_elementRef
|
||
constructor(private elementRef: ElementRef) {} | ||
|
||
ngAfterViewInit() { |
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.
Should be ngAfterContentInit
, since technically a @Directive
doesn't have a view, only content.
ngAfterViewInit() { | ||
this.observer = new MutationObserver(mutations => mutations.forEach(() => this.event.emit())); | ||
|
||
this.observer.observe(this.elementRef.nativeElement, {characterData: true, subtree: true}); |
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.
Don't need childList
?
@Directive({ | ||
selector: '[cdk-observe-content]' | ||
}) | ||
export class MdMutationObserver { |
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.
Call this class just ObserveContent
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.
Oops..
@@ -150,6 +148,12 @@ export class MdTabHeader { | |||
} | |||
} | |||
|
|||
_checkPagination() { |
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.
_updatePagination
? Also needs a method description
|
||
fixture.componentInstance.text = 'text'; | ||
fixture.detectChanges(); | ||
}); |
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.
Why not have below
class ComponentWithTextContent {
contentUpdated = jasmine.createSpy('contentUpdated');
}
And then in the test
let fixture = TestBed.createComponent(ComponentWithTextContent);
fixture.detectChanges();
fixture.componentInstance.contentUpdated.reset();
fixture.componentInstance.text = 'Taco';
fixture.detectChanges();
expect(fixture.componentInstance.contentUpdated.calls.count())
.toBe(1, 'Expected exactly one content change event');
fixture.componentInstance.text = 'Chocolate';
fixture.detectChanges();
expect(fixture.componentInstance.contentUpdated.calls.count())
.toBe(2, 'Expected exactly two content change events');
(similar for other test)
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.
Just tried this locally and I saw that the async stuff doesn't really work. Seems like zones doesn't play well with MutationObserver
...
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.
Hmm, Zones is supposed to understand MutationObserver
, I'll have to check with Misko on this tomorrow.
650d09b
to
9b2404b
Compare
@Directive({ | ||
selector: '[cdk-observe-content]' | ||
}) | ||
export class ObserveContent { |
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.
You should add an annotation to the class: export class ObserveContent implements OnDestroy, AfterContentInit
.
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.
When you're right, you're right!
5fa3c58
to
f839831
Compare
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 you fix the lint error?
@@ -150,6 +148,16 @@ export class MdTabHeader { | |||
} | |||
} | |||
|
|||
/** | |||
* Updating the view whether pagination should be enabled or 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.
Don't use @private
JsDoc, it messes up stuff when we sync into google
56d06b1
to
d0b4fc8
Compare
@andrewseguin can you review as well? |
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, small thing about the output
export class ObserveContent implements AfterContentInit, OnDestroy { | ||
private _observer: MutationObserver; | ||
|
||
@Output('cdk-observe-content') event = new EventEmitter<void>(); |
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.
Should this be camelcased?
- Uses observe-changes directive that emit an event when the mutation observer notifies a change fixes angular#2155
d0b4fc8
to
c8a6e6c
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. |
fixes #2155