bug(autocomplete): Setting input value from code does not update autocomplete selected item
- Lenguaje dominante
- TypeScript
- Estrellas
- 25k
- Forks
- 6.8k
- Merge medio
- 1 d 8 h
- PR fusionados (30 d)
- 91
Descripción
### 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
Guía de contribución
Línea de trabajo
Comienza con la reproducción en src/app/example-component.ts del StackBlitz enlazado y sigue cómo afecta a la autocompletación borrar el FormControl o el valor de entrada. Confirma el comportamiento en Chrome o Firefox: después de borrar y volver a enfocar, la opción seleccionada anteriormente ya no debería mostrar su marca de verificación ni la indicación visual de selección en primer plano.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- angular, typescript
- Área
- frontend
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Tranquilo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 55/100