Bug
The opened event should be sent when the panel is open.
When an autocomplete panel is initialized with no options, but they are added later, the opened event is never sent.
Open https://stackblitz.com/edit/bug-autocomplete-opened, then type something to open the autocomplete panel.
The event is used to obtain a reference to the autocomplete panel鈥檚 HTML element, as soon as it is open.
See MatAutcompleteTrigger:open the overlay is created but the event is never emitted because is no MatOption available.
See MatAutocompleteTrigger:_subscribeToClosingActions, when changes are detected, the panel becomes visible but no event is emitted.
A possible fix is to emit events in MatAutocomplete:_setVisibility, but it鈥檒l introduce a new (and possible unexpected) behavior to the component.
If you look in the DOM, the autocomplete is open, but it's not visible because there aren't any options.
I'm hitting the same issue. We are extending the mat-autocomplete to provide some additional functionality on top of it, but the opened and closed emitters are not always emitting values which is breaking our code. This makes the mat-autocomplete component kind of useless in our use case.
I don't see a point of keeping the autocomplete's panel state opened when there aren't any options to display. I assumed that when there are no options display the panel would automatically transition to state closed.
The fix of this is very desired. I faced with this issue also, not only open event is broken, close event also does not work as expected.
There is an example https://stackblitz.com/edit/angular-qvhrap?file=app/autocomplete-overview-example.html
'Open' event emits almost always but if something happened with close event an 'open' event doesn't emit. A 'close' event fires each time after the mouse has been clicked but if do continue writing text the panel would be closed but event would not be fired.
@josephperrott Excuse me, but could someone change priority to higher level ? Cant implement huge part of logic depended on that two events, looking for workaround :(
Wow, this seems to be a very high priority list. I am using an observable to trigger the options panel and the open function never gets called.
Still waiting for a fix or a workaround.
Sadly, I have solved this by manually emitting an 'opened event'.
// On your component
@ViewChild(MatAutocomplete) autoComplete: MatAutocomplete;
....
// On your function
myFn(): void {
this.autoComplete.opened.emit();
}
@dalepo Thanks for solution, but it's seem's dont fixe the issue, it's maybe du to ReactiveFormsModule,
MatInputModule,
BrowserAnimationsModule,
and specially the last one, cause animation dont show, but in my verification console.log show the values selected in the array after a filter due to writing content into input !
If any one find a solution to fixe the bug let us know !
Thx
Most helpful comment
The fix of this is very desired. I faced with this issue also, not only open event is broken, close event also does not work as expected.
There is an example https://stackblitz.com/edit/angular-qvhrap?file=app/autocomplete-overview-example.html
'Open' event emits almost always but if something happened with close event an 'open' event doesn't emit. A 'close' event fires each time after the mouse has been clicked but if do continue writing text the panel would be closed but event would not be fired.
@josephperrott Excuse me, but could someone change priority to higher level ? Cant implement huge part of logic depended on that two events, looking for workaround :(