angular / angular/components

MatAutocomplete does not always emit opened event

Aperta
#13,650 9 commenti 16 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

#### Bug, feature request, or proposal:
Bug

#### What is the expected behavior?
The `opened` event should be sent when the panel is open.

#### What is the current behavior?
When an autocomplete panel is initialized with no options, but they are added later, the `opened` event is never sent.

#### What are the steps to reproduce?
Open [https://stackblitz.com/edit/bug-autocomplete-opened](https://stackblitz.com/edit/bug-autocomplete-opened), then type something to open the autocomplete panel.

#### What is the use-case or motivation for changing an existing behavior?
The event is used to obtain a reference to the autocomplete panel’s HTML element, as soon as it is open.

#### Which versions of Angular, Material, OS, TypeScript, browsers are affected?
- Material 6.4.7
- Angular 6.1.0

#### Is there anything else we should know?
- See [MatAutcompleteTrigger:open](https://github.com/angular/material2/blob/2e4a51180b0074d59c1584c82fb8959f52660124/src/lib/autocomplete/autocomplete-trigger.ts#L609) the overlay is created but the event is never emitted because is no `MatOption` available.

- See [MatAutocompleteTrigger:_subscribeToClosingActions](https://github.com/angular/material2/blob/2e4a51180b0074d59c1584c82fb8959f52660124/src/lib/autocomplete/autocomplete-trigger.ts#L495), when changes are detected, the panel becomes visible but no event is emitted.

A possible fix is to emit events in [MatAutocomplete:_setVisibility](https://github.com/angular/material2/blob/2e4a51180b0074d59c1584c82fb8959f52660124/src/lib/autocomplete/autocomplete.ts#L196), but it’ll introduce a new (and possible unexpected) behavior to the component.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia con MatAutocompleteTrigger:open e _subscribeToClosingActions in src/lib/autocomplete/autocomplete-trigger.ts, quindi esamina MatAutocomplete:_setVisibility in src/lib/autocomplete/autocomplete.ts. Esegui la riproduzione StackBlitz collegata e verifica che la digitazione dopo l’aggiunta delle opzioni emetta opened quando il pannello diventa visibile, senza introdurre emissioni impreviste.

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
55/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.