@@ -15,7 +15,7 @@ import {
15
15
TemplateRef
16
16
} from '@angular/core' ;
17
17
import { DOCUMENT } from '@angular/common' ;
18
- import { Positioning } from 'positioning' ;
18
+ import { PlacementArray , positionElements } from 'positioning' ;
19
19
import { CalendarEvent } from 'calendar-utils' ;
20
20
21
21
@Component ( {
@@ -57,7 +57,7 @@ export class CalendarTooltipWindowComponent {
57
57
export class CalendarTooltipDirective implements OnDestroy {
58
58
@Input ( 'mwlCalendarTooltip' ) contents : string ; // tslint:disable-line no-input-rename
59
59
60
- @Input ( 'tooltipPlacement' ) placement : string = 'top ' ; // tslint:disable-line no-input-rename
60
+ @Input ( 'tooltipPlacement' ) placement : PlacementArray = 'auto ' ; // tslint:disable-line no-input-rename
61
61
62
62
@Input ( 'tooltipTemplate' ) customTemplate : TemplateRef < any > ; // tslint:disable-line no-input-rename
63
63
@@ -67,7 +67,6 @@ export class CalendarTooltipDirective implements OnDestroy {
67
67
68
68
private tooltipFactory : ComponentFactory < CalendarTooltipWindowComponent > ;
69
69
private tooltipRef : ComponentRef < CalendarTooltipWindowComponent > ;
70
- private positioning : Positioning = new Positioning ( ) ;
71
70
72
71
constructor (
73
72
private elementRef : ElementRef ,
@@ -105,7 +104,6 @@ export class CalendarTooltipDirective implements OnDestroy {
105
104
[ ]
106
105
) ;
107
106
this . tooltipRef . instance . contents = this . contents ;
108
- this . tooltipRef . instance . placement = this . placement ;
109
107
this . tooltipRef . instance . customTemplate = this . customTemplate ;
110
108
this . tooltipRef . instance . event = this . event ;
111
109
if ( this . appendToBody ) {
@@ -126,20 +124,19 @@ export class CalendarTooltipDirective implements OnDestroy {
126
124
}
127
125
}
128
126
129
- private positionTooltip ( ) : void {
127
+ private positionTooltip ( previousPosition ?: string ) : void {
130
128
if ( this . tooltipRef ) {
131
- const targetPosition : ClientRect = this . positioning . positionElements (
129
+ this . tooltipRef . changeDetectorRef . detectChanges ( ) ;
130
+ this . tooltipRef . instance . placement = positionElements (
132
131
this . elementRef . nativeElement ,
133
132
this . tooltipRef . location . nativeElement . children [ 0 ] ,
134
133
this . placement ,
135
134
this . appendToBody
136
135
) ;
137
-
138
- const elm : HTMLElement = this . tooltipRef . location . nativeElement
139
- . children [ 0 ] ;
140
-
141
- this . renderer . setStyle ( elm , 'top' , `${ targetPosition . top } px` ) ;
142
- this . renderer . setStyle ( elm , 'left' , `${ targetPosition . left } px` ) ;
136
+ // keep re-positioning the tooltip until the arrow position doesn't make a difference
137
+ if ( previousPosition !== this . tooltipRef . instance . placement ) {
138
+ this . positionTooltip ( this . tooltipRef . instance . placement ) ;
139
+ }
143
140
}
144
141
}
145
142
}
0 commit comments