@@ -30,27 +30,39 @@ import {Overlay} from './overlay';
30
30
import { OverlayConfig } from './overlay-config' ;
31
31
import { OverlayRef } from './overlay-ref' ;
32
32
import {
33
- ConnectedOverlayPositionChange ,
34
- ConnectionPositionPair ,
35
- } from './position/connected-position' ;
36
- import { ConnectedPositionStrategy } from './position/connected-position-strategy ' ;
33
+ FlexibleConnectedPositionStrategy ,
34
+ ConnectedPosition ,
35
+ } from './position/flexible- connected-position-strategy ' ;
36
+ import { ConnectedOverlayPositionChange } from './position/connected-position' ;
37
37
import { RepositionScrollStrategy , ScrollStrategy } from './scroll/index' ;
38
38
39
39
40
40
/** Default set of positions for the overlay. Follows the behavior of a dropdown. */
41
- const defaultPositionList = [
42
- new ConnectionPositionPair (
43
- { originX : 'start' , originY : 'bottom' } ,
44
- { overlayX : 'start' , overlayY : 'top' } ) ,
45
- new ConnectionPositionPair (
46
- { originX : 'start' , originY : 'top' } ,
47
- { overlayX : 'start' , overlayY : 'bottom' } ) ,
48
- new ConnectionPositionPair (
49
- { originX : 'end' , originY : 'top' } ,
50
- { overlayX : 'end' , overlayY : 'bottom' } ) ,
51
- new ConnectionPositionPair (
52
- { originX : 'end' , originY : 'bottom' } ,
53
- { overlayX : 'end' , overlayY : 'top' } ) ,
41
+ const defaultPositionList : ConnectedPosition [ ] = [
42
+ {
43
+ originX : 'start' ,
44
+ originY : 'bottom' ,
45
+ overlayX : 'start' ,
46
+ overlayY : 'top'
47
+ } ,
48
+ {
49
+ originX : 'start' ,
50
+ originY : 'top' ,
51
+ overlayX : 'start' ,
52
+ overlayY : 'bottom'
53
+ } ,
54
+ {
55
+ originX : 'end' ,
56
+ originY : 'top' ,
57
+ overlayX : 'end' ,
58
+ overlayY : 'bottom'
59
+ } ,
60
+ {
61
+ originX : 'end' ,
62
+ originY : 'bottom' ,
63
+ overlayX : 'end' ,
64
+ overlayY : 'top'
65
+ }
54
66
] ;
55
67
56
68
/** Injection token that determines the scroll handling while the connected overlay is open. */
@@ -101,21 +113,22 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
101
113
private _backdropSubscription = Subscription . EMPTY ;
102
114
private _offsetX : number = 0 ;
103
115
private _offsetY : number = 0 ;
104
- private _position : ConnectedPositionStrategy ;
116
+ private _position : FlexibleConnectedPositionStrategy ;
105
117
106
118
/** Origin for the connected overlay. */
107
119
@Input ( 'cdkConnectedOverlayOrigin' ) origin : CdkOverlayOrigin ;
108
120
109
121
/** Registered connected position pairs. */
110
- @Input ( 'cdkConnectedOverlayPositions' ) positions : ConnectionPositionPair [ ] ;
122
+ @Input ( 'cdkConnectedOverlayPositions' ) positions : ConnectedPosition [ ] ;
111
123
112
124
/** The offset in pixels for the overlay connection point on the x-axis */
113
125
@Input ( 'cdkConnectedOverlayOffsetX' )
114
126
get offsetX ( ) : number { return this . _offsetX ; }
115
127
set offsetX ( offsetX : number ) {
116
128
this . _offsetX = offsetX ;
129
+
117
130
if ( this . _position ) {
118
- this . _position . withOffsetX ( offsetX ) ;
131
+ this . _setPositions ( this . _position ) ;
119
132
}
120
133
}
121
134
@@ -124,8 +137,9 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
124
137
get offsetY ( ) { return this . _offsetY ; }
125
138
set offsetY ( offsetY : number ) {
126
139
this . _offsetY = offsetY ;
140
+
127
141
if ( this . _position ) {
128
- this . _position . withOffsetY ( offsetY ) ;
142
+ this . _setPositions ( this . _position ) ;
129
143
}
130
144
}
131
145
@@ -174,8 +188,8 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
174
188
* @deletion -target 6.0.0
175
189
*/
176
190
@Input ( 'positions' )
177
- get _deprecatedPositions ( ) : ConnectionPositionPair [ ] { return this . positions ; }
178
- set _deprecatedPositions ( _positions : ConnectionPositionPair [ ] ) { this . positions = _positions ; }
191
+ get _deprecatedPositions ( ) : ConnectedPosition [ ] { return this . positions ; }
192
+ set _deprecatedPositions ( _positions : ConnectedPosition [ ] ) { this . positions = _positions ; }
179
193
180
194
/**
181
195
* @deprecated
@@ -362,28 +376,42 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
362
376
}
363
377
364
378
/** Returns the position strategy of the overlay to be set on the overlay config */
365
- private _createPositionStrategy ( ) : ConnectedPositionStrategy {
366
- const primaryPosition = this . positions [ 0 ] ;
367
- const originPoint = { originX : primaryPosition . originX , originY : primaryPosition . originY } ;
368
- const overlayPoint = { overlayX : primaryPosition . overlayX , overlayY : primaryPosition . overlayY } ;
379
+ private _createPositionStrategy ( ) : FlexibleConnectedPositionStrategy {
369
380
const strategy = this . _overlay . position ( )
370
- . connectedTo ( this . origin . elementRef , originPoint , overlayPoint )
371
- . withOffsetX ( this . offsetX )
372
- . withOffsetY ( this . offsetY )
381
+ . flexibleConnectedTo ( this . origin . elementRef )
382
+ // Turn off all of the flexible positioning features for now to have it behave
383
+ // the same way as the old ConnectedPositionStrategy and to avoid breaking changes.
384
+ // TODO(crisbeto): make these on by default and add inputs for them
385
+ // next time we do breaking changes.
386
+ . withFlexibleHeight ( false )
387
+ . withFlexibleWidth ( false )
388
+ . withPush ( false )
389
+ . withGrowAfterOpen ( false )
373
390
. withLockedPosition ( this . lockPosition ) ;
374
391
375
- for ( let i = 1 ; i < this . positions . length ; i ++ ) {
376
- strategy . withFallbackPosition (
377
- { originX : this . positions [ i ] . originX , originY : this . positions [ i ] . originY } ,
378
- { overlayX : this . positions [ i ] . overlayX , overlayY : this . positions [ i ] . overlayY }
379
- ) ;
380
- }
381
-
382
- strategy . onPositionChange . subscribe ( pos => this . positionChange . emit ( pos ) ) ;
392
+ this . _setPositions ( strategy ) ;
393
+ strategy . positionChanges . subscribe ( p => this . positionChange . emit ( p ) ) ;
383
394
384
395
return strategy ;
385
396
}
386
397
398
+ /**
399
+ * Sets the primary and fallback positions of a positions strategy,
400
+ * based on the current directive inputs.
401
+ */
402
+ private _setPositions ( positionStrategy : FlexibleConnectedPositionStrategy ) {
403
+ const positions : ConnectedPosition [ ] = this . positions . map ( pos => ( {
404
+ originX : pos . originX ,
405
+ originY : pos . originY ,
406
+ overlayX : pos . overlayX ,
407
+ overlayY : pos . overlayY ,
408
+ offsetX : this . offsetX ,
409
+ offsetY : this . offsetY
410
+ } ) ) ;
411
+
412
+ positionStrategy . withPositions ( positions ) ;
413
+ }
414
+
387
415
/** Attaches the overlay and subscribes to backdrop clicks if backdrop exists */
388
416
private _attachOverlay ( ) {
389
417
if ( ! this . _overlayRef ) {
@@ -404,7 +432,6 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
404
432
} ) ;
405
433
}
406
434
407
- this . _position . withDirection ( this . dir ) ;
408
435
this . _overlayRef . setDirection ( this . dir ) ;
409
436
410
437
if ( ! this . _overlayRef . hasAttached ( ) ) {
0 commit comments