You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MatAutocomplete selection option event order #18650
P4A relatively minor issue that is not relevant to core functionsarea: material/autocompletefeatureLabel used to distinguish feature request from other issues
The current order of events when selecting an option from MatAutocomplete is as follows:
Update the NgModel
Bring focus to the autocomplete
Emit select event which calls @output() optionSelected
This is the code which executes this logic.
MatAutocompleteTrigger.prototype._setValueAndClose =
function (event) {
if (event && event.source) {
this._clearPreviousSelectedOption(event.source);
this._setTriggerValue(event.source.value);
this._onChange(event.source.value);
this._element.nativeElement.focus();
this.autocomplete._emitSelectEvent(event.source);
}
this.closePanel();
};
I am proposing to call the focus() event after this.autocomplete._emitSelectEvent(event.source);
The issue is if you want to test the current selected model value in the focus() event it will be incorrect because the setting of the model happens after focus is called.
Use Case
In the focus event we are testing if the model value is blank and if so then open the panel to give suggested search items.
Rather than using the focus even, couldn't you use the optionSelected event instead? It's not a big deal to change the behavior, but I'm trying to understand what the use case is.
P4A relatively minor issue that is not relevant to core functionsarea: material/autocompletefeatureLabel used to distinguish feature request from other issues
Activity
crisbeto commentedon Feb 29, 2020
Rather than using the
focuseven, couldn't you use theoptionSelectedevent instead? It's not a big deal to change the behavior, but I'm trying to understand what the use case is.raygig commentedon Feb 29, 2020
We are trying to build a suggestion feature which is activated when the autocomplete is focused and the ngmodel is null.
Currently this breaks with this scenario.
#5 happens because the focus event triggers before ngmodel is set.
fix(autocomplete): restore focus after emitting option selected event
fix(autocomplete): restore focus after emitting option selected event
fix(autocomplete): restore focus after emitting option selected event (…
fix(autocomplete): restore focus after emitting option selected event (…
angular-automatic-lock-bot commentedon Feb 18, 2022
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.
fix(autocomplete): restore focus after emitting option selected event (…