Skip to content

Commit

Permalink
fix(cdk/overlay): fix wrong overflow calculation (#17791)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people committed Aug 6, 2020
1 parent df7156e commit d2b499d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Expand Up @@ -611,8 +611,8 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {

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

Expand Down
16 changes: 13 additions & 3 deletions src/material-experimental/popover-edit/popover-edit.spec.ts
Expand Up @@ -182,7 +182,7 @@ class ElementDataSource extends DataSource<PeriodicElement> {

@Component({
template: `
<div #table style="margin: 16px">
<div #table style="margin: 16px; max-width: 90vw; max-height: 90vh;">
<mat-table editable [dataSource]="dataSource">
<ng-container matColumnDef="before">
<mat-cell *matCellDef="let element">
Expand Down Expand Up @@ -219,7 +219,12 @@ class ElementDataSource extends DataSource<PeriodicElement> {
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
</mat-table>
</div>
`
`,
styles: [`
mat-table {
margin: 16px;
}
`]
})
class MatFlexTableInCell extends BaseTestComponent {
displayedColumns = ['before', 'name', 'weight'];
Expand Down Expand Up @@ -265,7 +270,12 @@ class MatFlexTableInCell extends BaseTestComponent {
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
<div>
`
`,
styles: [`
table {
margin: 16px;
}
`]
})
class MatTableInCell extends BaseTestComponent {
displayedColumns = ['before', 'name', 'weight'];
Expand Down

0 comments on commit d2b499d

Please sign in to comment.