Hide autocomplete options panel on disabled or add hidePanel method.
See original GitHub issueBug, feature request, or proposal:
(More a suggestion as a bug. But a unwanted behavior of users.) Hide the options panel of autocomplete if the input element goes disabled. Or add a method to hide the panel in an official way.
What is the expected behavior?
Hide the option panel if the input is disabled. Also if the panel was displayed before the input disabled.
What is the current behavior?
The option panel still displayed. The user can select an item. Also if the input is disabled. But note: Only when the clear button stops propagation. That’s a correct behavior but not as the user expected.
What are the steps to reproduce?
- User selects an item from mat-autocomplete. (works as expected.)
- User clicks again on the input to view the option, (ok)
- The user clicks on the clear button on the right (matSuffix). The method on the clear button disables the input and sets event.stopPropagation() to prevent the underlayed input get focused. Result: The options panel still showing. The user can select an item. Also if the input is disabled.
What is the use-case or motivation for changing an existing behavior?
The clear button stops the propagation becuase the button is over the input element. I do not want to select the input on clear-button clicked. But the stopPropagation() enables this “bug” here descripted. (User can select a option also if input is disabled after clear)
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
5.0.1
Is there anything else we should know?
It’s possible to hide the panel like
myAutoComplete.panel.nativeElement.hidden = true;
But this will still hide the panel after user clicked into the input again. Until the user clicked outside of the input an the input again.
Solutions:
- Always hide the panel if the input is disabled.
- Add a method like showPanel for hidePanel. But do not simple hidden = true of the native element. Because of the issue explained above.
I’ve found no hidePanel() method. Only a showPanel() method. What’s wrong with a hide method?
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
The
MatAutocompleteTrigger
directive hasopenPanel
andclosePanel
methods, however it doesn’t look like we’ve exported it through the template. You should still be able to get a reference to it through aViewChild
though. E.g.autoTests
is referring to theMatAutocomplete
, not theMatAutocompleteTrigger
. After #9703 gets in, you should be able to get a hold of the trigger instance like this:Until the PR gets released, you can refer to https://github.com/angular/material2/issues/9687#issuecomment-361732004.