bug(autocomplete): Setting input value from code does not update autocomplete selected item
- Vorherrschende Sprache
- TypeScript
- Sterne
- 25k
- Forks
- 6.8k
- Ø Merge
- 1 T. 8 Std.
- Gemergte PRs (30 T.)
- 91
Beschreibung
### Is this a regression?
- [ ] Yes, this behavior used to work in the previous version
### The previous version in which this bug was not present was
_No response_
### Description
Autocomplete works beautifully when working from the user inputs.
When we set the value from the code-behind (either via FormControl or on the element directly) the selected option does not update.
In the attached example we need to clear the input from code, but the previously selected option still has the "selected" checkmark and foreground color.
### Reproduction
StackBlitz link: [components-issue-hmgdm3](https://stackblitz.com/edit/components-issue-hmgdm3?file=src%2Fapp%2Fexample-component.ts)
Steps to reproduce:
1. Select an option from the autocomplete
2. Clear the selection by using the button
3. Focus the input and you can see the previously selected option still having the "selected" indicators (checkmark and foreground)
### Expected Behavior
The autocomplete is supposed to remove the selected indication on the last selected option when the value of our input is cleared
### Actual Behavior
The autocomplete keeps previously selected option as "selected"
### Environment
- Angular: 16.2.1
- CDK/Material: 16.2.1
- Browser(s): Chrome, Firefox latest
- Operating System (e.g. Windows, macOS, Ubuntu): Windows 11
Beitragsleitfaden
Rechercherichtung
Beginne mit der Reproduktion in src/app/example-component.ts aus dem verlinkten StackBlitz und verfolge, wie sich das Leeren des FormControl oder des Eingabewerts auf die Autovervollständigung auswirkt. Bestätige das Verhalten in Chrome oder Firefox: Nach dem Leeren und erneuten Fokussieren sollte die zuvor ausgewählte Option weder ihr Häkchen noch die hervorgehobene Anzeige der Auswahl zeigen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- angular, typescript
- Bereich
- frontend
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 55/100