Skip to content

Commit

Permalink
fix(module:tooltip): is not aligned on first display (#7457)
Browse files Browse the repository at this point in the history
close #7453
  • Loading branch information
volvachev committed Jun 15, 2022
1 parent ba6bade commit 23a2fd5
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions components/tooltip/base.ts
Expand Up @@ -23,8 +23,8 @@ import {
ViewChild,
ViewContainerRef
} from '@angular/core';
import { Subject } from 'rxjs';
import { distinctUntilChanged, takeUntil } from 'rxjs/operators';
import { asapScheduler, Subject } from 'rxjs';
import { delay, distinctUntilChanged, filter, takeUntil } from 'rxjs/operators';

import { NzConfigService, PopConfirmConfig, PopoverConfig } from 'ng-zorro-antd/core/config';
import { NzNoAnimationDirective } from 'ng-zorro-antd/core/no-animation';
Expand Down Expand Up @@ -184,11 +184,25 @@ export abstract class NzTooltipBaseDirective implements OnChanges, OnDestroy, Af

this.initProperties();

this.component.nzVisibleChange
.pipe(distinctUntilChanged(), takeUntil(this.destroy$))
.subscribe((visible: boolean) => {
this.internalVisible = visible;
this.visibleChange.emit(visible);
const ngVisibleChange$ = this.component.nzVisibleChange.pipe(distinctUntilChanged());

ngVisibleChange$.pipe(takeUntil(this.destroy$)).subscribe((visible: boolean) => {
this.internalVisible = visible;
this.visibleChange.emit(visible);
});

// In some cases, the rendering takes into account the height at which the `arrow` is in wrong place,
// so `cdk` sets the container position incorrectly.
// To avoid this, after placing the `arrow` in the correct position, we should `re-calculate` the position of the `overlay`.
ngVisibleChange$
.pipe(
filter((visible: boolean) => visible),
delay(0, asapScheduler),
filter(() => Boolean(this.component?.overlay?.overlayRef)),
takeUntil(this.destroy$)
)
.subscribe(() => {
this.component?.updatePosition();
});
}

Expand Down

0 comments on commit 23a2fd5

Please sign in to comment.