1
- import { Component , ViewChild } from '@angular/core' ;
1
+ import { Component , ElementRef , ViewChild } from '@angular/core' ;
2
2
import { By } from '@angular/platform-browser' ;
3
3
import {
4
4
ComponentFixture ,
@@ -28,7 +28,10 @@ import {
28
28
ConnectedOverlayPositionChange ,
29
29
ConnectionPositionPair ,
30
30
} from './position/connected-position' ;
31
- import { FlexibleConnectedPositionStrategy } from './position/flexible-connected-position-strategy' ;
31
+ import {
32
+ FlexibleConnectedPositionStrategy ,
33
+ FlexibleConnectedPositionStrategyOrigin ,
34
+ } from './position/flexible-connected-position-strategy' ;
32
35
import { Subject } from 'rxjs' ;
33
36
34
37
@@ -408,6 +411,21 @@ describe('Overlay directives', () => {
408
411
expect ( Math . floor ( triggerRect . bottom ) ) . toBe ( Math . floor ( overlayRect . top ) ) ;
409
412
} ) ;
410
413
414
+ it ( 'should be able to use non-directive origin' , ( ) => {
415
+ const testComponent = fixture . componentInstance ;
416
+
417
+ testComponent . triggerOverride = testComponent . nonDirectiveTrigger ;
418
+ testComponent . isOpen = true ;
419
+ fixture . detectChanges ( ) ;
420
+
421
+ const triggerRect =
422
+ fixture . nativeElement . querySelector ( '#nonDirectiveTrigger' ) . getBoundingClientRect ( ) ;
423
+ const overlayRect = getPaneElement ( ) . getBoundingClientRect ( ) ;
424
+
425
+ expect ( Math . floor ( triggerRect . left ) ) . toBe ( Math . floor ( overlayRect . left ) ) ;
426
+ expect ( Math . floor ( triggerRect . bottom ) ) . toBe ( Math . floor ( overlayRect . top ) ) ;
427
+ } ) ;
428
+
411
429
it ( 'should update the positions if they change after init' , ( ) => {
412
430
const trigger = fixture . nativeElement . querySelector ( '#trigger' ) ;
413
431
@@ -674,6 +692,7 @@ describe('Overlay directives', () => {
674
692
template : `
675
693
<button cdk-overlay-origin id="trigger" #trigger="cdkOverlayOrigin">Toggle menu</button>
676
694
<button cdk-overlay-origin id="otherTrigger" #otherTrigger="cdkOverlayOrigin">Toggle menu</button>
695
+ <button id="nonDirectiveTrigger" #nonDirectiveTrigger>Toggle menu</button>
677
696
678
697
<ng-template cdk-connected-overlay
679
698
[cdkConnectedOverlayOpen]="isOpen"
@@ -708,6 +727,7 @@ class ConnectedOverlayDirectiveTest {
708
727
@ViewChild ( CdkConnectedOverlay ) connectedOverlayDirective : CdkConnectedOverlay ;
709
728
@ViewChild ( 'trigger' ) trigger : CdkOverlayOrigin ;
710
729
@ViewChild ( 'otherTrigger' ) otherTrigger : CdkOverlayOrigin ;
730
+ @ViewChild ( 'nonDirectiveTrigger' ) nonDirectiveTrigger : ElementRef < HTMLElement > ;
711
731
712
732
isOpen = false ;
713
733
width : number | string ;
@@ -717,7 +737,7 @@ class ConnectedOverlayDirectiveTest {
717
737
minHeight : number | string ;
718
738
offsetX : number ;
719
739
offsetY : number ;
720
- triggerOverride : CdkOverlayOrigin ;
740
+ triggerOverride : CdkOverlayOrigin | FlexibleConnectedPositionStrategyOrigin ;
721
741
hasBackdrop : boolean ;
722
742
disableClose : boolean ;
723
743
viewportMargin : number ;
0 commit comments