Skip to content

Commit 23a2fd5

Browse files
authored
fix(module:tooltip): is not aligned on first display (#7457)
close #7453
1 parent ba6bade commit 23a2fd5

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

components/tooltip/base.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import {
2323
ViewChild,
2424
ViewContainerRef
2525
} from '@angular/core';
26-
import { Subject } from 'rxjs';
27-
import { distinctUntilChanged, takeUntil } from 'rxjs/operators';
26+
import { asapScheduler, Subject } from 'rxjs';
27+
import { delay, distinctUntilChanged, filter, takeUntil } from 'rxjs/operators';
2828

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

185185
this.initProperties();
186186

187-
this.component.nzVisibleChange
188-
.pipe(distinctUntilChanged(), takeUntil(this.destroy$))
189-
.subscribe((visible: boolean) => {
190-
this.internalVisible = visible;
191-
this.visibleChange.emit(visible);
187+
const ngVisibleChange$ = this.component.nzVisibleChange.pipe(distinctUntilChanged());
188+
189+
ngVisibleChange$.pipe(takeUntil(this.destroy$)).subscribe((visible: boolean) => {
190+
this.internalVisible = visible;
191+
this.visibleChange.emit(visible);
192+
});
193+
194+
// In some cases, the rendering takes into account the height at which the `arrow` is in wrong place,
195+
// so `cdk` sets the container position incorrectly.
196+
// To avoid this, after placing the `arrow` in the correct position, we should `re-calculate` the position of the `overlay`.
197+
ngVisibleChange$
198+
.pipe(
199+
filter((visible: boolean) => visible),
200+
delay(0, asapScheduler),
201+
filter(() => Boolean(this.component?.overlay?.overlayRef)),
202+
takeUntil(this.destroy$)
203+
)
204+
.subscribe(() => {
205+
this.component?.updatePosition();
192206
});
193207
}
194208

0 commit comments

Comments
 (0)