Skip to content

Commit 6ddcd04

Browse files
Gooblesandrewseguin
authored andcommitted
fix(cdk/overlay): fix wrong overflow calculation (#17791)
* fix(cdk/overlay): fix wrong overflow calculation overflowBottom is currently calculated with viewport.bottom (which could be any number from the height of the viewport to as large as your page is) calculating the overflow should just be difference between "overlay.height added to the current coordinate on the overlay container" and the height of the viewport, not the height of the entire page. * fix(popover-edit): fix failing test Tested component should always fit within the viewport. Pane dimensions should be approximately compared. * avoid flaky errors due to narrow viewport width Co-authored-by: Gobius Dolhain <Goobles@users.noreply.github.com> Co-authored-by: Andrew Seguin <andrewjs@google.com> (cherry picked from commit d2b499d)
1 parent 237a6cc commit 6ddcd04

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/cdk/overlay/position/flexible-connected-position-strategy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,8 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
611611

612612
// Determine how much the overlay goes outside the viewport on each
613613
// side, which we'll use to decide which direction to push it.
614-
const overflowRight = Math.max(start.x + overlay.width - viewport.right, 0);
615-
const overflowBottom = Math.max(start.y + overlay.height - viewport.bottom, 0);
614+
const overflowRight = Math.max(start.x + overlay.width - viewport.width, 0);
615+
const overflowBottom = Math.max(start.y + overlay.height - viewport.height, 0);
616616
const overflowTop = Math.max(viewport.top - scrollPosition.top - start.y, 0);
617617
const overflowLeft = Math.max(viewport.left - scrollPosition.left - start.x, 0);
618618

src/material-experimental/popover-edit/popover-edit.spec.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class ElementDataSource extends DataSource<PeriodicElement> {
182182

183183
@Component({
184184
template: `
185-
<div #table style="margin: 16px">
185+
<div #table style="margin: 16px; max-width: 90vw; max-height: 90vh;">
186186
<mat-table editable [dataSource]="dataSource">
187187
<ng-container matColumnDef="before">
188188
<mat-cell *matCellDef="let element">
@@ -219,7 +219,12 @@ class ElementDataSource extends DataSource<PeriodicElement> {
219219
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
220220
</mat-table>
221221
</div>
222-
`
222+
`,
223+
styles: [`
224+
mat-table {
225+
margin: 16px;
226+
}
227+
`]
223228
})
224229
class MatFlexTableInCell extends BaseTestComponent {
225230
displayedColumns = ['before', 'name', 'weight'];
@@ -265,7 +270,12 @@ class MatFlexTableInCell extends BaseTestComponent {
265270
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
266271
</table>
267272
<div>
268-
`
273+
`,
274+
styles: [`
275+
table {
276+
margin: 16px;
277+
}
278+
`]
269279
})
270280
class MatTableInCell extends BaseTestComponent {
271281
displayedColumns = ['before', 'name', 'weight'];

0 commit comments

Comments
 (0)