angular / angular/components

bug(autocomplete): optionSelected and onChangeCallback is called before the animation completes

Aperta
#29,326 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
area: material/autocomplete P4
Lingua principale
TypeScript
Stelle
25k
Fork
6.8k
Merge medio
1g 8h
PR unite (30g)
91

Descrizione

### Is this a regression?

- [X] Yes, this behavior used to work in the previous version

### The previous version in which this bug was not present was

v16.1.8

### Description

There is a _setValueAndClose method in the MatAutocompleteTrigger class that doesn't take into account the time to complete the animation, this has even been flagged todo but still not fixed. Currently, if we in optionSelected decide to clear the array used in ngFor for mat-option, we will get the array cleared before the panel closes and there will be a corresponding jump

![image](https://github.com/angular/components/assets/73141739/0a03a21b-848b-4ae2-af92-35a50599d2a7)

@crisbeto

### Reproduction

StackBlitz link: https://components-issue-v4ujjj.stackblitz.io
Steps to reproduce:
1. put the focus in the field
2. pick a value from the list

### Expected Behavior

the optionSelected event will be called after the animation is complete, the menu will not jump after the array is cleared

### Actual Behavior

optionSelected event was triggered without waiting for the animation to complete, clearing the array caused the panel to jump

### Environment

- Angular: 16.2.12
- CDK/Material: 16.2.14
- Browser(s): google chrome v126.0.6478.127
- Operating System (e.g. Windows, macOS, Ubuntu): Windows 10

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia con la classe MatAutocompleteTrigger e il suo metodo _setValueAndClose, quindi riproduci il comportamento usando lo StackBlitz collegato, selezionando un'opzione mentre svuoti l'array mat-option ngFor in optionSelected. Confronta la tempistica degli eventi con l'animazione del pannello di completamento automatico; il lavoro è completato quando optionSelected e onChangeCallback non fanno saltare il pannello prima del completamento dell'animazione.

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

Valutazione

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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.