@@ -69,7 +69,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
69
69
private _viewportRect : ClientRect ;
70
70
71
71
/** Amount of space that must be maintained between the overlay and the edge of the viewport. */
72
- private _viewportMargin : number = 0 ;
72
+ private _viewportMargin = 0 ;
73
73
74
74
/** The Scrollable containers used to check scrollable view properties on position change. */
75
75
private scrollables : CdkScrollable [ ] = [ ] ;
@@ -101,6 +101,12 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
101
101
/** Subscription to viewport size changes. */
102
102
private _resizeSubscription = Subscription . EMPTY ;
103
103
104
+ /** Default offset for the overlay along the x axis. */
105
+ private _offsetX = 0 ;
106
+
107
+ /** Default offset for the overlay along the y axis. */
108
+ private _offsetY = 0 ;
109
+
104
110
/** Observable sequence of position changes. */
105
111
positionChanges : Observable < ConnectedOverlayPositionChange > =
106
112
this . _positionChanges . asObservable ( ) ;
@@ -366,6 +372,24 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
366
372
return this ;
367
373
}
368
374
375
+ /**
376
+ * Sets the default offset for the overlay's connection point on the x-axis.
377
+ * @param offset New offset in the X axis.
378
+ */
379
+ withDefaultOffsetX ( offset : number ) : this {
380
+ this . _offsetX = offset ;
381
+ return this ;
382
+ }
383
+
384
+ /**
385
+ * Sets the default offset for the overlay's connection point on the y-axis.
386
+ * @param offset New offset in the Y axis.
387
+ */
388
+ withDefaultOffsetY ( offset : number ) : this {
389
+ this . _offsetY = offset ;
390
+ return this ;
391
+ }
392
+
369
393
/**
370
394
* Gets the (x, y) coordinate of a connection point on the origin based on a relative position.
371
395
*/
@@ -431,14 +455,16 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
431
455
position : ConnectedPosition ) : OverlayFit {
432
456
433
457
let { x, y} = point ;
458
+ let offsetX = this . _getOffset ( position , 'x' ) ;
459
+ let offsetY = this . _getOffset ( position , 'y' ) ;
434
460
435
461
// Account for the offsets since they could push the overlay out of the viewport.
436
- if ( position . offsetX ) {
437
- x += position . offsetX ;
462
+ if ( offsetX ) {
463
+ x += offsetX ;
438
464
}
439
465
440
- if ( position . offsetY ) {
441
- y += position . offsetY ;
466
+ if ( offsetY ) {
467
+ y += offsetY ;
442
468
}
443
469
444
470
// How much the overlay would overflow at this position, on each side.
@@ -721,13 +747,15 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
721
747
// cases where the element doesn't have anything to "push off of". Finally, this works
722
748
// better both with flexible and non-flexible positioning.
723
749
let transformString = ' ' ;
750
+ let offsetX = this . _getOffset ( position , 'x' ) ;
751
+ let offsetY = this . _getOffset ( position , 'y' ) ;
724
752
725
- if ( position . offsetX ) {
726
- transformString += `translateX(${ position . offsetX } px)` ;
753
+ if ( offsetX ) {
754
+ transformString += `translateX(${ offsetX } px)` ;
727
755
}
728
756
729
- if ( position . offsetY ) {
730
- transformString += `translateY(${ position . offsetY } px)` ;
757
+ if ( offsetY ) {
758
+ transformString += `translateY(${ offsetY } px)` ;
731
759
}
732
760
733
761
styles . transform = transformString . trim ( ) ;
@@ -869,6 +897,17 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
869
897
private _isRtl ( ) {
870
898
return this . _overlayRef . getConfig ( ) . direction === 'rtl' ;
871
899
}
900
+
901
+ /** Retrieves the offset of a position along the x or y axis. */
902
+ private _getOffset ( position : ConnectedPosition , axis : 'x' | 'y' ) {
903
+ if ( axis === 'x' ) {
904
+ // We don't do something like `position['offset' + axis]` in
905
+ // order to avoid breking minifiers that rename properties.
906
+ return position . offsetX == null ? this . _offsetX : position . offsetX ;
907
+ }
908
+
909
+ return position . offsetY == null ? this . _offsetY : position . offsetY ;
910
+ }
872
911
}
873
912
874
913
/** A simple (x, y) coordinate. */
0 commit comments