Skip to content

bug(CdkOverlay): CdkOverlay incorrectly calculates viewport bounds #21350

Description

@jerrodrs

Reproduction

https://stackblitz.com/edit/components-issue-yh1yjm?file=src/app/example-component.ts

Steps to reproduce:

  1. Spawn a flexible position based overlay.
  2. Make overlay contents height larger than viewport height such that overflow occurs.
  3. Make viewport height a floating point number with decimal portion between .0 to .5.
  4. The overlay will now overflow out of the viewport bounds.
  5. Make the viewport height a floating point number between .5 to next whole number, or a whole number.
  6. The overlay will now correctly stay within the viewport bounds.

Notes:
If you just try slowly resizing the window height while the overlay is open, you will see it bounce in and out of the viewport as the window height cycles between bad and good numbers.

Problem is that viewport height is a rounded number, and overlay height is a floating point. Therefore when viewport rounds down, the following check fails.

if (overlay.height <= viewport.height) {

To compare the two numbers, the rounding needs to be consistent.

Expected Behavior

Flexible dimension overlay should always remain within viewport bounds.

Actual Behavior

Flexible dimension overlay does not remain within viewport bounds when viewport height rounds down.

Environment

  • Angular: 10.2.3
  • CDK/Material: 10.2.7
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows 10

Metadata

Metadata

Assignees

Labels

P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: cdk/overlay

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions