angular / components

Component infrastructure and Material Design components for Angular
https://material.angular.io
MIT License
24.37k stars 6.75k forks source link

bug(autocomplete): reset input value doesn't update the selected option #20878

Open aitboudad opened 4 years ago

aitboudad commented 4 years ago

Reproduction

When an autocomplete control is reset, the selected option still hold the .mat-selected class.

https://stackblitz.com/edit/angular-ufhza2 Steps to reproduce:

1) Open the autocomplete 2) Select an entry 3) Click reset 4) Open the autocomplete again

Selection_052

Expected Behavior

mat-selected class should be removed when autocomplete is empty

Environment

FloppyNotFound commented 4 years ago

Please note that there is also a second, possibly connected issue, with the autocomplete control. When an initial selection is applied (programmatically), the mat-selected class is not set.

Reproduction steps (also see connected and referenced ticket with simple demo solution):

Replace model = { }; with model = { state: "Alabama" };

Expected behavior: the .mat-selected class is applied, the selected item has a red background

Actual behavior: the .mat-selected class is not applied, the selected item looks just like the others and has a white background.