@@ -17,6 +17,7 @@ import {
1717import { Observable , Subscription , Subject } from 'rxjs' ;
1818import { OverlayRef } from '../overlay-ref' ;
1919import { isElementScrolledOutsideView , isElementClippedByScrolling } from './scroll-clip' ;
20+ import { coerceCssPixelValue } from '@angular/cdk/coercion' ;
2021
2122
2223// TODO: refactor clipping detection into a separate thing (part of scrolling module)
@@ -665,29 +666,29 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
665666 styles . bottom = '' ;
666667 styles . height = '100%' ;
667668 } else {
668- styles . height = ` ${ boundingBoxRect . height } px` ;
669- styles . top = boundingBoxRect . top != null ? ` ${ boundingBoxRect . top } px` : '' ;
670- styles . bottom = boundingBoxRect . bottom != null ? ` ${ boundingBoxRect . bottom } px` : '' ;
669+ styles . top = coerceCssPixelValue ( boundingBoxRect . top ) ;
670+ styles . bottom = coerceCssPixelValue ( boundingBoxRect . bottom ) ;
671+ styles . height = coerceCssPixelValue ( boundingBoxRect . height ) ;
671672 }
672673
673674 if ( ! this . _hasFlexibleWidth || this . _isPushed ) {
674675 styles . left = '0' ;
675676 styles . right = '' ;
676677 styles . width = '100%' ;
677678 } else {
678- styles . width = ` ${ boundingBoxRect . width } px` ;
679- styles . left = boundingBoxRect . left != null ? ` ${ boundingBoxRect . left } px` : '' ;
680- styles . right = boundingBoxRect . right != null ? ` ${ boundingBoxRect . right } px` : '' ;
679+ styles . left = coerceCssPixelValue ( boundingBoxRect . left ) ;
680+ styles . right = coerceCssPixelValue ( boundingBoxRect . right ) ;
681+ styles . width = coerceCssPixelValue ( boundingBoxRect . width ) ;
681682 }
682683
683684 const maxHeight = this . _overlayRef . getConfig ( ) . maxHeight ;
684685 if ( maxHeight && this . _hasFlexibleHeight ) {
685- styles . maxHeight = formatCssUnit ( maxHeight ) ;
686+ styles . maxHeight = coerceCssPixelValue ( maxHeight ) ;
686687 }
687688
688689 const maxWidth = this . _overlayRef . getConfig ( ) . maxWidth ;
689690 if ( maxWidth && this . _hasFlexibleWidth ) {
690- styles . maxWidth = formatCssUnit ( maxWidth ) ;
691+ styles . maxWidth = coerceCssPixelValue ( maxWidth ) ;
691692 }
692693
693694 this . _lastBoundingBoxSize = boundingBoxRect ;
@@ -800,7 +801,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
800801 const documentHeight = this . _document . documentElement . clientHeight ;
801802 styles . bottom = `${ documentHeight - ( overlayPoint . y + this . _overlayRect . height ) } px` ;
802803 } else {
803- styles . top = ` ${ overlayPoint . y } px` ;
804+ styles . top = coerceCssPixelValue ( overlayPoint . y ) ;
804805 }
805806
806807 return styles ;
@@ -835,7 +836,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
835836 const documentWidth = this . _document . documentElement . clientWidth ;
836837 styles . right = `${ documentWidth - ( overlayPoint . x + this . _overlayRect . width ) } px` ;
837838 } else {
838- styles . left = ` ${ overlayPoint . x } px` ;
839+ styles . left = coerceCssPixelValue ( overlayPoint . x ) ;
839840 }
840841
841842 return styles ;
@@ -971,11 +972,6 @@ export interface ConnectedPosition {
971972 offsetY ?: number ;
972973}
973974
974- // TODO: move to common place
975- function formatCssUnit ( value : number | string ) {
976- return typeof value === 'string' ? value as string : `${ value } px` ;
977- }
978-
979975/** Shallow-extends a stylesheet object with another stylesheet object. */
980976function extendStyles ( dest : CSSStyleDeclaration , source : CSSStyleDeclaration ) : CSSStyleDeclaration {
981977 for ( let key in source ) {
0 commit comments