Skip to content

Hide panel of autocomplete on focus #16401

@Swoox

Description

@Swoox

Feature Description

What I would like to see is an option to disable the panel on focus.

Use Case

When a user focus on an autocomplete input I want the panel to be not opened.
After input it will open the panel.

What I tried

I have an FormArray within that FormArray I have multiple autocompletes.
For the phone the autocompletes are wrapped in an expansion panel.
When either the page open with default expansion panel or when a epansion panel get clicked it will selected the first input, in this case an autocomplete.
The autocomplete open with the panel open.
I can close it with this.autoCompletes['_results'][0].closePanel(); which is a queryList of MatAutocompleteTrigger.
This will close the panel when I open the page.
But it doesn't if I open an expansion panel.
So I tried to add this on the focus event.
It seems that the panel will open after the focus event.
So the panel get closed before the panel get opened.

Also tried a timeout but this will first visible show the panel and then close it.

Solution

Either make the panel open earlier.
Make an input to disable the panel on focus.

Stackblitz

https://angular-sng8gx.stackblitz.io
Query list is not working for some reason..

Edit

I changed it to this, it seems to work better but after the second input it get registered sadly.
It seems matAutocompleteDisabled is set to late.

(focus)="closedPanel=true;"
(input)="getData($event.target).then(closedPanel=false);"
[matAutocompleteDisabled]="closedPanel"

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureThis issue represents a new feature or feature request rather than a bug or bug fix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions