Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(cdk/scrolling): Virtual viewport not working correctly when using mat-menu #29395

Open
1 task
DerMagereStudent opened this issue Jul 8, 2024 · 1 comment
Labels
area: cdk/scrolling area: material/menu P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@DerMagereStudent
Copy link

DerMagereStudent commented Jul 8, 2024

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

The minimal reproduction of the bug shows that the viewport height is not correctly handled which leads to a lot of empty space within the viewport area since list items are not created properly. Also when scrolling through the list, closing and reopening the menu, the list is empty. Resizing the window solves all the problems. I currently got rid of the problems by creating a wrapper for the list and manually triggering the resize event if the component is visible:

constructor(public _eRef: ElementRef, private ngZone: NgZone) { }

ngAfterViewInit() {
  this.observer = new IntersectionObserver(entries => {
    entries.forEach(entry => {
      if (entry.isIntersecting) {
        this.triggerResizeEvent();
      }
    });
  });
  this.observer.observe(this._eRef.nativeElement)
}

private triggerResizeEvent() {
  this.ngZone.runOutsideAngular(() => {
    window.dispatchEvent(new Event('resize'));
  });
}

Reproduction

StackBlitz link: https://stackblitz.com/edit/stackblitz-starters-57cqqc?file=src%2Fapp%2Fviewport-error.component.html
Steps to reproduce:

  1. open the mat-menu
  2. the viewport is half empty
  3. resize the window
  4. viewport filled properly

Steps to reproduce:

  1. open the mat-menu
  2. scroll through list
  3. close and reopen the menu
  4. viewport empty

Expected Behavior

The viewport should be completely filled with options

Actual Behavior

The viewport is not fully filled. The list items are not created properly

Environment

Angular CLI: 18.0.7
Node: 18.20.3
Package Manager: npm 10.2.3
OS: linux x64

Angular: 18.0.6
... animations, cdk, cdk-experimental, common, compiler
... compiler-cli, core, forms, material, platform-browser
... platform-browser-dynamic, router

Package Version

@angular-devkit/architect 0.1800.7
@angular-devkit/build-angular 18.0.7
@angular-devkit/core 18.0.7
@angular-devkit/schematics 18.0.7
@angular/cli 18.0.7
@schematics/angular 18.0.7
rxjs 7.8.1
typescript 5.4.5
zone.js 0.14.7

@DerMagereStudent DerMagereStudent added the needs triage This issue needs to be triaged by the team label Jul 8, 2024
@DerMagereStudent DerMagereStudent changed the title @cdk-experimental ScrollingModule autosize not working correctly when using mat-menu bug(cdk-experimental/scrolling): ScrollingModule autosize not working correctly when using mat-menu Jul 8, 2024
@DerMagereStudent DerMagereStudent changed the title bug(cdk-experimental/scrolling): ScrollingModule autosize not working correctly when using mat-menu bug(cdk-experimental/scrolling): Virtual viewport autosize not working correctly when using mat-menu Jul 8, 2024
@DerMagereStudent DerMagereStudent changed the title bug(cdk-experimental/scrolling): Virtual viewport autosize not working correctly when using mat-menu bug(cdk/scrolling): Virtual viewport not working correctly when using mat-menu Jul 12, 2024
@DerMagereStudent
Copy link
Author

I adjusted the issue and the minimal reproduction, since I noticed it has nothing to do with the experimental autosize directive. Also occurs when cdk-experimental is not installed,

@amysorto amysorto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent area: cdk/scrolling area: material/menu and removed needs triage This issue needs to be triaged by the team labels Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: cdk/scrolling area: material/menu P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

No branches or pull requests

2 participants