@@ -7,7 +7,10 @@ import {ESCAPE} from '@angular/cdk/keycodes';
7
7
import { CdkConnectedOverlay , OverlayModule , CdkOverlayOrigin } from './index' ;
8
8
import { OverlayContainer } from './overlay-container' ;
9
9
import { ConnectedPositionStrategy } from './position/connected-position-strategy' ;
10
- import { ConnectedOverlayPositionChange } from './position/connected-position' ;
10
+ import {
11
+ ConnectedOverlayPositionChange ,
12
+ ConnectionPositionPair ,
13
+ } from './position/connected-position' ;
11
14
12
15
13
16
describe ( 'Overlay directives' , ( ) => {
@@ -268,6 +271,42 @@ describe('Overlay directives', () => {
268
271
expect ( Math . floor ( triggerRect . bottom ) ) . toBe ( Math . floor ( overlayRect . top ) ) ;
269
272
} ) ;
270
273
274
+ it ( 'should update the positions if they change after init' , ( ) => {
275
+ const trigger = fixture . nativeElement . querySelector ( '#trigger' ) ;
276
+
277
+ trigger . style . position = 'fixed' ;
278
+ trigger . style . top = '200px' ;
279
+ trigger . style . left = '200px' ;
280
+
281
+ fixture . componentInstance . isOpen = true ;
282
+ fixture . detectChanges ( ) ;
283
+
284
+ let triggerRect = trigger . getBoundingClientRect ( ) ;
285
+ let overlayRect = getPaneElement ( ) . getBoundingClientRect ( ) ;
286
+
287
+ expect ( Math . floor ( triggerRect . left ) ) . toBe ( Math . floor ( overlayRect . left ) ) ;
288
+ expect ( Math . floor ( triggerRect . bottom ) ) . toBe ( Math . floor ( overlayRect . top ) ) ;
289
+
290
+ fixture . componentInstance . isOpen = false ;
291
+ fixture . detectChanges ( ) ;
292
+
293
+ fixture . componentInstance . positionOverrides = [ {
294
+ originX : 'end' ,
295
+ originY : 'bottom' ,
296
+ overlayX : 'start' ,
297
+ overlayY : 'top'
298
+ } ] ;
299
+
300
+ fixture . componentInstance . isOpen = true ;
301
+ fixture . detectChanges ( ) ;
302
+
303
+ triggerRect = trigger . getBoundingClientRect ( ) ;
304
+ overlayRect = getPaneElement ( ) . getBoundingClientRect ( ) ;
305
+
306
+ expect ( Math . floor ( triggerRect . right ) ) . toBe ( Math . floor ( overlayRect . left ) ) ;
307
+ expect ( Math . floor ( triggerRect . bottom ) ) . toBe ( Math . floor ( overlayRect . top ) ) ;
308
+ } ) ;
309
+
271
310
} ) ;
272
311
273
312
describe ( 'outputs' , ( ) => {
@@ -328,7 +367,8 @@ describe('Overlay directives', () => {
328
367
[hasBackdrop]="hasBackdrop" backdropClass="mat-test-class"
329
368
(backdropClick)="backdropClicked=true" [offsetX]="offsetX" [offsetY]="offsetY"
330
369
(positionChange)="positionChangeHandler($event)" (attach)="attachHandler()"
331
- (detach)="detachHandler()" [minWidth]="minWidth" [minHeight]="minHeight">
370
+ (detach)="detachHandler()" [minWidth]="minWidth" [minHeight]="minHeight"
371
+ [cdkConnectedOverlayPositions]="positionOverrides">
332
372
<p>Menu content</p>
333
373
</ng-template>` ,
334
374
} )
@@ -348,6 +388,7 @@ class ConnectedOverlayDirectiveTest {
348
388
hasBackdrop : boolean ;
349
389
backdropClicked = false ;
350
390
positionChangeHandler = jasmine . createSpy ( 'positionChangeHandler' ) ;
391
+ positionOverrides : ConnectionPositionPair [ ] ;
351
392
attachHandler = jasmine . createSpy ( 'attachHandler' ) . and . callFake ( ( ) => {
352
393
this . attachResult =
353
394
this . connectedOverlayDirective . overlayRef . overlayElement . querySelector ( 'p' ) as HTMLElement ;
0 commit comments