Skip to content

Commit cd2cd5a

Browse files
committed
fix(tooltip): prevent infinite loop error when positioning tooltip
Fixes #1046
1 parent ca3220b commit cd2cd5a

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

projects/angular-calendar/src/modules/common/calendar-tooltip.directive.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export class CalendarTooltipDirective implements OnDestroy, OnChanges {
150150
this.cancelTooltipDelay$.next();
151151
}
152152

153-
private positionTooltip(previousPosition?: string): void {
153+
private positionTooltip(previousPositions: string[] = []): void {
154154
if (this.tooltipRef) {
155155
this.tooltipRef.changeDetectorRef.detectChanges();
156156
this.tooltipRef.instance.placement = positionElements(
@@ -160,8 +160,13 @@ export class CalendarTooltipDirective implements OnDestroy, OnChanges {
160160
this.appendToBody
161161
);
162162
// keep re-positioning the tooltip until the arrow position doesn't make a difference
163-
if (previousPosition !== this.tooltipRef.instance.placement) {
164-
this.positionTooltip(this.tooltipRef.instance.placement);
163+
if (
164+
previousPositions.indexOf(this.tooltipRef.instance.placement) === -1
165+
) {
166+
this.positionTooltip([
167+
...previousPositions,
168+
this.tooltipRef.instance.placement
169+
]);
165170
}
166171
}
167172
}

0 commit comments

Comments
 (0)