-
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(tooltip): not working properly with ChangeDetectionStrategy.OnPush #2721
Conversation
|
||
// Call change detection manually so tooltip will also work | ||
// if any parent component has set the ChangeDetectionStrategy to OnPush | ||
this._ref.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.
@jelbourn is there a way to find out if a parent component has set the ChangeDetectionStrategy
to OnPush
or not so we can skip this line?
|
||
// Call change detection manually so tooltip will also work | ||
// if any parent component has set the ChangeDetectionStrategy to OnPush | ||
this._ref.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.
I think rather than always triggering a ChangeDetection
we should just mark for a new check.
We are doing this in other components as well.
https://angular.io/docs/js/latest/api/core/index/ChangeDetectorRef-class.html
@@ -286,7 +287,7 @@ export class TooltipComponent { | |||
/** Subject for notifying that the tooltip has been hidden from the view */ | |||
private _onHide: Subject<any> = new Subject(); | |||
|
|||
constructor(@Optional() private _dir: Dir) {} | |||
constructor(@Optional() private _dir: Dir, private _ref: ChangeDetectorRef) {} |
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.
_ref
is not very precise. It should be _changeDetectorRef
@devversion getting error in e2e test - maybe restart?
|
@thomaspink Done. Never saw such an error on the CI...
|
@devversion seemed to work now - strange Thanks |
@devversion trying to figure out whats happening here #2733 so i can submit test cases for this PR |
Added tests |
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 good, just a couple minor comments
@@ -76,6 +90,43 @@ describe('MdTooltip', () => { | |||
expect(tooltipDirective._tooltipInstance).toBeNull(); | |||
})); | |||
|
|||
it('should show and hide the tooltip if changeDetection is OnPush', fakeAsync(() => { |
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 move this test to a separate describe block called "with OnPush" as a sibling to the existing "basic usage" block? Then you can do the createComponent
in the beforeEach
.
tick(500); | ||
|
||
// Make sure tooltip is shown to the user and animation has finished | ||
const tooltipElement = <HTMLElement>overlayContainerElement.querySelector('.md-tooltip'); |
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.
Prefer the as HTMLElement
syntax
@jelbourn implemented as suggested. |
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, thanks!
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 #2713