@@ -5,9 +5,11 @@ import {applyCssTransform} from '../../style/apply-transform';
5
5
import {
6
6
ConnectionPositionPair ,
7
7
OriginConnectionPosition ,
8
- OverlayConnectionPosition
8
+ OverlayConnectionPosition ,
9
+ ConnectedOverlayPositionChange
9
10
} from './connected-position' ;
10
-
11
+ import { Subject } from 'rxjs/Subject' ;
12
+ import { Observable } from 'rxjs/Observable' ;
11
13
12
14
/**
13
15
* A strategy for positioning overlays. Using this strategy, an overlay is given an
@@ -36,6 +38,12 @@ export class ConnectedPositionStrategy implements PositionStrategy {
36
38
/** The origin element against which the overlay will be positioned. */
37
39
private _origin : HTMLElement ;
38
40
41
+ private _onPositionChange : Subject < ConnectedOverlayPositionChange > = new Subject ( ) ;
42
+
43
+ /** Emits an event when a fallback position is used. */
44
+ get onPositionChange ( ) : Observable < ConnectedOverlayPositionChange > {
45
+ return this . _onPositionChange . asObservable ( ) ;
46
+ }
39
47
40
48
constructor (
41
49
private _connectedTo : ElementRef ,
@@ -64,6 +72,7 @@ export class ConnectedPositionStrategy implements PositionStrategy {
64
72
// We use the viewport rect to determine whether a position would go off-screen.
65
73
const viewportRect = this . _viewportRuler . getViewportRect ( ) ;
66
74
let firstOverlayPoint : Point = null ;
75
+ let isFirstPosition = true ;
67
76
68
77
// We want to place the overlay in the first of the preferred positions such that the
69
78
// overlay fits on-screen.
@@ -77,8 +86,12 @@ export class ConnectedPositionStrategy implements PositionStrategy {
77
86
// If the overlay in the calculated position fits on-screen, put it there and we're done.
78
87
if ( this . _willOverlayFitWithinViewport ( overlayPoint , overlayRect , viewportRect ) ) {
79
88
this . _setElementPosition ( element , overlayPoint ) ;
89
+ if ( ! isFirstPosition ) {
90
+ this . _onPositionChange . next ( new ConnectedOverlayPositionChange ( pos ) ) ;
91
+ }
80
92
return Promise . resolve ( null ) ;
81
93
}
94
+ isFirstPosition = false ;
82
95
}
83
96
84
97
// TODO(jelbourn): fallback behavior for when none of the preferred positions fit on-screen.
0 commit comments