@@ -581,16 +581,19 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
581
581
*/
582
582
private _calculateBoundingBoxRect ( origin : Point , position : ConnectedPosition ) : BoundingBoxRect {
583
583
const viewport = this . _viewportRect ;
584
+ const isRtl = this . _isRtl ( ) ;
584
585
let height , top , bottom ;
585
586
586
587
if ( position . overlayY === 'top' ) {
587
588
// Overlay is opening "downward" and thus is bound by the bottom viewport edge.
588
589
top = origin . y ;
589
590
height = viewport . bottom - origin . y ;
590
591
} else if ( position . overlayY === 'bottom' ) {
591
- // Overlay is opening "upward" and thus is bound by the top viewport edge.
592
- bottom = viewport . height - origin . y + this . _viewportMargin ;
593
- height = viewport . height - bottom ;
592
+ // Overlay is opening "upward" and thus is bound by the top viewport edge. We need to add
593
+ // the viewport margin back in, because the viewport rect is narrowed down to remove the
594
+ // margin, whereas the `origin` position is calculated based on its `ClientRect`.
595
+ bottom = viewport . height - origin . y + this . _viewportMargin * 2 ;
596
+ height = viewport . height - bottom + this . _viewportMargin ;
594
597
} else {
595
598
// If neither top nor bottom, it means that the overlay
596
599
// is vertically centered on the origin point.
@@ -608,13 +611,13 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
608
611
609
612
// The overlay is opening 'right-ward' (the content flows to the right).
610
613
const isBoundedByRightViewportEdge =
611
- ( position . overlayX === 'start' && ! this . _isRtl ( ) ) ||
612
- ( position . overlayX === 'end' && this . _isRtl ( ) ) ;
614
+ ( position . overlayX === 'start' && ! isRtl ) ||
615
+ ( position . overlayX === 'end' && isRtl ) ;
613
616
614
617
// The overlay is opening 'left-ward' (the content flows to the left).
615
618
const isBoundedByLeftViewportEdge =
616
- ( position . overlayX === 'end' && ! this . _isRtl ( ) ) ||
617
- ( position . overlayX === 'start' && this . _isRtl ( ) ) ;
619
+ ( position . overlayX === 'end' && ! isRtl ) ||
620
+ ( position . overlayX === 'start' && isRtl ) ;
618
621
619
622
let width , left , right ;
620
623
@@ -887,7 +890,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
887
890
return {
888
891
top : scrollPosition . top + this . _viewportMargin ,
889
892
left : scrollPosition . left + this . _viewportMargin ,
890
- right : scrollPosition . left + width - this . _viewportMargin ,
893
+ right : scrollPosition . left + width - this . _viewportMargin ,
891
894
bottom : scrollPosition . top + height - this . _viewportMargin ,
892
895
width : width - ( 2 * this . _viewportMargin ) ,
893
896
height : height - ( 2 * this . _viewportMargin ) ,
0 commit comments