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
autocomplete panel doesn't pop up when triggering focus on the input programatically #3106
I'm not at all familiar with using ngZone, but it seems like this change fixes it
autocomplete.ts/** Panel should hide itself when the option list is empty. */_setVisibility(){// Promise.resolve().then(() => this.showPanel = !!this.options.length);this.zone.run(()=>this.showPanel=!!this.options.length);}
The issue actually seems to be that clicking a button to focus the autocomplete triggers an _outsideClickStream event just after it has been opened, thus causing it to immediately close.
As a workaround, you can use a setTimeout to focus it after the outside click event fires.
Below code did the trick for me assuming focus is already on input field.
import { MdAutocompleteTrigger} from '@angular/material';
@ViewChild(MdAutocompleteTrigger) trigger;
this.trigger._onChange("");
this.trigger.openPanel();
Reacted by lz-2932, Mat Polutta, vinga, Max Terry, Francesco, Thibaut T., eliascole-zs2, Matias Fernandez Martinez, Tayfun Adakoğlu, iAboelsuod and 6 more
Is there any workaround or fix for this issue?
I'm having a dropdown that fetches data dynamically from the server. When I click on the chip-list field it doesn't open autocomplete list until I input any character in that.
Activity
willshowell commentedon Feb 23, 2017
I'm not at all familiar with using
ngZone, but it seems like this change fixes itbergben commentedon Jun 6, 2017
Is there any workaround for this for now?
willshowell commentedon Jun 6, 2017
The issue actually seems to be that clicking a button to focus the autocomplete triggers an
_outsideClickStreamevent just after it has been opened, thus causing it to immediately close.As a workaround, you can use a setTimeout to focus it after the outside click event fires.
http://plnkr.co/edit/cKYxnL9f8hV2Uklucd5d?p=preview
willshowell commentedon Jun 6, 2017
Alternatively use
stopPropagation()on the click eventhttp://plnkr.co/edit/m4W7zAGulSaxhPqqlpzp?p=preview
willshowell commentedon Jul 24, 2017
Here's an updated plunker https://plnkr.co/edit/gyarTLKwyt97CX9304Fd?p=preview
bruteforce commentedon Sep 21, 2017
Below code did the trick for me assuming focus is already on input field.
mpolutta commentedon Apr 2, 2018
Combined willshowell and bruteforce solutions to solve for our 508 compliance scenario. Clear button is another scenario:
openAutoSearchPanel() {
if (this.searchText.length === 0) {
this.autoSearchInputTrigger._onChange('');
this.autoSearchInputTrigger.openPanel();
}
}
clearSearchText() {
console.log('>>> clearing searchText');
this.searchText = '';
/// hack: Another reported workaround - Allow the ClickStream to finish executing via setTimeout.
/// #3106
setTimeout(() => {
this.autoSearchInput.nativeElement.focus();
this.openAutoSearchPanel();
});
}
Charius commentedon Apr 28, 2018
yeah, got the same issue while implement custom field with autocomplete, timeout works, but this is pretty weird
maxterry commentedon Jul 13, 2018
Any update on this...?
tombolador commentedon Jul 31, 2018
+1, any updates?
mischkl commentedon Sep 17, 2018
This problem also affects chiplist inputs with autocomplete. 😢
RajendrasinhParmar commentedon Sep 22, 2018
Is there any workaround or fix for this issue?
I'm having a dropdown that fetches data dynamically from the server. When I click on the chip-list field it doesn't open autocomplete list until I input any character in that.
13 remaining items
fix(material/autocomplete): closing immediately when input is focused…
Lms24 commentedon Jul 2, 2021
How is this bug still open? This is a seriously annoying bug which requires an annoying workaround when used together with reactive forms.
fix(material/autocomplete): closing immediately when input is focused…
KissBalazs commentedon Oct 27, 2021
This bug is still present, and makes testing with
Harnessquite difficult.This code:
will fail in roughly half of the time, as the panel gets closed immediatly in those cases.
crisbeto commentedon Oct 27, 2021
There's a pending PR that should make the autocomplete harness a bit more consistent in unit tests #23795.
fix(material/autocomplete): closing immediately when input is focused…
fix(material/autocomplete): closing immediately when input is focused…
fix(material/autocomplete): closing immediately when input is focused…
mischkl commentedon Feb 22, 2022
Glad to see it finally got fixed! 🥳 Thanks @andrewseguin
angular-automatic-lock-bot commentedon Mar 25, 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(material/autocomplete): closing immediately when input is focused…