@@ -69,7 +69,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
6969 private _viewportRect : ClientRect ;
7070
7171 /** 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 ;
7373
7474 /** The Scrollable containers used to check scrollable view properties on position change. */
7575 private scrollables : CdkScrollable [ ] = [ ] ;
@@ -101,6 +101,12 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
101101 /** Subscription to viewport size changes. */
102102 private _resizeSubscription = Subscription . EMPTY ;
103103
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+
104110 /** Observable sequence of position changes. */
105111 positionChanges : Observable < ConnectedOverlayPositionChange > =
106112 this . _positionChanges . asObservable ( ) ;
@@ -366,6 +372,24 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
366372 return this ;
367373 }
368374
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+
369393 /**
370394 * Gets the (x, y) coordinate of a connection point on the origin based on a relative position.
371395 */
@@ -431,14 +455,16 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
431455 position : ConnectedPosition ) : OverlayFit {
432456
433457 let { x, y} = point ;
458+ let offsetX = this . _getOffset ( position , 'x' ) ;
459+ let offsetY = this . _getOffset ( position , 'y' ) ;
434460
435461 // 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 ;
438464 }
439465
440- if ( position . offsetY ) {
441- y += position . offsetY ;
466+ if ( offsetY ) {
467+ y += offsetY ;
442468 }
443469
444470 // How much the overlay would overflow at this position, on each side.
@@ -721,13 +747,15 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
721747 // cases where the element doesn't have anything to "push off of". Finally, this works
722748 // better both with flexible and non-flexible positioning.
723749 let transformString = ' ' ;
750+ let offsetX = this . _getOffset ( position , 'x' ) ;
751+ let offsetY = this . _getOffset ( position , 'y' ) ;
724752
725- if ( position . offsetX ) {
726- transformString += `translateX(${ position . offsetX } px)` ;
753+ if ( offsetX ) {
754+ transformString += `translateX(${ offsetX } px)` ;
727755 }
728756
729- if ( position . offsetY ) {
730- transformString += `translateY(${ position . offsetY } px)` ;
757+ if ( offsetY ) {
758+ transformString += `translateY(${ offsetY } px)` ;
731759 }
732760
733761 styles . transform = transformString . trim ( ) ;
@@ -869,6 +897,17 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
869897 private _isRtl ( ) {
870898 return this . _overlayRef . getConfig ( ) . direction === 'rtl' ;
871899 }
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+ }
872911}
873912
874913/** A simple (x, y) coordinate. */
0 commit comments