@@ -30,28 +30,40 @@ 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
import { DOCUMENT } from '@angular/common' ;
39
39
40
40
41
41
/** Default set of positions for the overlay. Follows the behavior of a dropdown. */
42
- const defaultPositionList = [
43
- new ConnectionPositionPair (
44
- { originX : 'start' , originY : 'bottom' } ,
45
- { overlayX : 'start' , overlayY : 'top' } ) ,
46
- new ConnectionPositionPair (
47
- { originX : 'start' , originY : 'top' } ,
48
- { overlayX : 'start' , overlayY : 'bottom' } ) ,
49
- new ConnectionPositionPair (
50
- { originX : 'end' , originY : 'top' } ,
51
- { overlayX : 'end' , overlayY : 'bottom' } ) ,
52
- new ConnectionPositionPair (
53
- { originX : 'end' , originY : 'bottom' } ,
54
- { overlayX : 'end' , overlayY : 'top' } ) ,
42
+ const defaultPositionList : ConnectedPosition [ ] = [
43
+ {
44
+ originX : 'start' ,
45
+ originY : 'bottom' ,
46
+ overlayX : 'start' ,
47
+ overlayY : 'top'
48
+ } ,
49
+ {
50
+ originX : 'start' ,
51
+ originY : 'top' ,
52
+ overlayX : 'start' ,
53
+ overlayY : 'bottom'
54
+ } ,
55
+ {
56
+ originX : 'end' ,
57
+ originY : 'top' ,
58
+ overlayX : 'end' ,
59
+ overlayY : 'bottom'
60
+ } ,
61
+ {
62
+ originX : 'end' ,
63
+ originY : 'bottom' ,
64
+ overlayX : 'end' ,
65
+ overlayY : 'top'
66
+ }
55
67
] ;
56
68
57
69
/** Injection token that determines the scroll handling while the connected overlay is open. */
@@ -102,21 +114,22 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
102
114
private _positionSubscription = Subscription . EMPTY ;
103
115
private _offsetX : number = 0 ;
104
116
private _offsetY : number = 0 ;
105
- private _position : ConnectedPositionStrategy ;
117
+ private _position : FlexibleConnectedPositionStrategy ;
106
118
107
119
/** Origin for the connected overlay. */
108
120
@Input ( 'cdkConnectedOverlayOrigin' ) origin : CdkOverlayOrigin ;
109
121
110
122
/** Registered connected position pairs. */
111
- @Input ( 'cdkConnectedOverlayPositions' ) positions : ConnectionPositionPair [ ] ;
123
+ @Input ( 'cdkConnectedOverlayPositions' ) positions : ConnectedPosition [ ] ;
112
124
113
125
/** The offset in pixels for the overlay connection point on the x-axis */
114
126
@Input ( 'cdkConnectedOverlayOffsetX' )
115
127
get offsetX ( ) : number { return this . _offsetX ; }
116
128
set offsetX ( offsetX : number ) {
117
129
this . _offsetX = offsetX ;
130
+
118
131
if ( this . _position ) {
119
- this . _position . withOffsetX ( offsetX ) ;
132
+ this . _setPositions ( this . _position ) ;
120
133
}
121
134
}
122
135
@@ -125,8 +138,9 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
125
138
get offsetY ( ) { return this . _offsetY ; }
126
139
set offsetY ( offsetY : number ) {
127
140
this . _offsetY = offsetY ;
141
+
128
142
if ( this . _position ) {
129
- this . _position . withOffsetY ( offsetY ) ;
143
+ this . _setPositions ( this . _position ) ;
130
144
}
131
145
}
132
146
@@ -164,8 +178,8 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
164
178
165
179
/** @deprecated */
166
180
@Input ( 'positions' )
167
- get _deprecatedPositions ( ) : ConnectionPositionPair [ ] { return this . positions ; }
168
- set _deprecatedPositions ( _positions : ConnectionPositionPair [ ] ) { this . positions = _positions ; }
181
+ get _deprecatedPositions ( ) : ConnectedPosition [ ] { return this . positions ; }
182
+ set _deprecatedPositions ( _positions : ConnectedPosition [ ] ) { this . positions = _positions ; }
169
183
170
184
/** @deprecated */
171
185
@Input ( 'offsetX' )
@@ -305,31 +319,36 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
305
319
}
306
320
307
321
/** Returns the position strategy of the overlay to be set on the overlay config */
308
- private _createPositionStrategy ( ) : ConnectedPositionStrategy {
309
- const pos = this . positions [ 0 ] ;
310
- const originPoint = { originX : pos . originX , originY : pos . originY } ;
311
- const overlayPoint = { overlayX : pos . overlayX , overlayY : pos . overlayY } ;
312
-
322
+ private _createPositionStrategy ( ) : FlexibleConnectedPositionStrategy {
313
323
const strategy = this . _overlay . position ( )
314
- . connectedTo ( this . origin . elementRef , originPoint , overlayPoint )
315
- . withOffsetX ( this . offsetX )
316
- . withOffsetY ( this . offsetY ) ;
324
+ . flexibleConnectedTo ( this . origin . elementRef )
325
+ . withFlexibleHeight ( false )
326
+ . withFlexibleWidth ( false )
327
+ . withPush ( false )
328
+ . withGrowAfterOpen ( false ) ;
317
329
318
- this . _handlePositionChanges ( strategy ) ;
330
+ this . _setPositions ( strategy ) ;
331
+ this . _positionSubscription =
332
+ strategy . positionChange . subscribe ( p => this . positionChange . emit ( p ) ) ;
319
333
320
334
return strategy ;
321
335
}
322
336
323
- private _handlePositionChanges ( strategy : ConnectedPositionStrategy ) : void {
324
- for ( let i = 1 ; i < this . positions . length ; i ++ ) {
325
- strategy . withFallbackPosition (
326
- { originX : this . positions [ i ] . originX , originY : this . positions [ i ] . originY } ,
327
- { overlayX : this . positions [ i ] . overlayX , overlayY : this . positions [ i ] . overlayY }
328
- ) ;
329
- }
330
-
331
- this . _positionSubscription =
332
- strategy . onPositionChange . subscribe ( pos => this . positionChange . emit ( pos ) ) ;
337
+ /**
338
+ * Sets the primary and fallback positions of a positions strategy,
339
+ * based on the current directive inputs.
340
+ */
341
+ private _setPositions ( positionStrategy : FlexibleConnectedPositionStrategy ) {
342
+ const positions : ConnectedPosition [ ] = this . positions . map ( pos => ( {
343
+ originX : pos . originX ,
344
+ originY : pos . originY ,
345
+ overlayX : pos . overlayX ,
346
+ overlayY : pos . overlayY ,
347
+ offsetX : this . offsetX ,
348
+ offsetY : this . offsetY
349
+ } ) ) ;
350
+
351
+ positionStrategy . withPositions ( positions ) ;
333
352
}
334
353
335
354
/** Attaches the overlay and subscribes to backdrop clicks if backdrop exists */
@@ -338,7 +357,6 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
338
357
this . _createOverlay ( ) ;
339
358
}
340
359
341
- this . _position . withDirection ( this . dir ) ;
342
360
this . _overlayRef . setDirection ( this . dir ) ;
343
361
this . _document . addEventListener ( 'keydown' , this . _escapeListener ) ;
344
362
0 commit comments