angular / angular/components

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

Aperta
#29,395 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
area: cdk/scrolling area: material/menu P3
Lingua principale
TypeScript
Stelle
25k
Fork
6.8k
Merge medio
1g 8h
PR unite (30g)
91

Descrizione

### 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:

```JS
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

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia dalla riproduzione collegata in StackBlitz e verifica i due casi segnalati: l'apertura del mat-menu lascia spazio vuoto nel viewport e, quando lo si riapre dopo lo scorrimento, l'elenco rimane vuoto finché non avviene un ridimensionamento. Traccia l'integrazione di Angular CDK virtual scrolling e mat-menu; il lavoro è completato quando il viewport viene riempito correttamente all'apertura e alla riapertura, senza inviare manualmente un evento di resize.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
angular, typescript
Ambito
frontend
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.