components icon indicating copy to clipboard operation
components copied to clipboard

MatAutocomplete does not always emit opened event

Open geanpeixoto opened this issue 6 years ago • 8 comments

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, 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?

A possible fix is to emit events in MatAutocomplete:_setVisibility, but it’ll introduce a new (and possible unexpected) behavior to the component.

geanpeixoto avatar Oct 17 '18 14:10 geanpeixoto

If you look in the DOM, the autocomplete is open, but it's not visible because there aren't any options.

crisbeto avatar Oct 18 '18 19:10 crisbeto

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.

steve-todorov avatar Oct 24 '18 11:10 steve-todorov

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

lexeek avatar Dec 04 '18 00:12 lexeek

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.

mohyeid avatar Jun 25 '19 23:06 mohyeid

Still waiting for a fix or a workaround.

Hassan-Moin avatar Jul 12 '19 12:07 Hassan-Moin

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 avatar Jul 14 '19 22:07 dalepo

@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

Dev25-00 avatar Feb 25 '20 12:02 Dev25-00

Create hidden element, it work with me <mat-option style="display: none;" [value]="">Hide

ghost avatar May 03 '24 09:05 ghost