angular / angular/components

bug(MatAutocomplete): MatAutocomplete + FormControl does not clear input correctly after option selection

Open
#25,809 4 comments 5 reactions 0 assignees View on GitHub
area: material/input P3
Dominant language
TypeScript
Stars
25k
Forks
6.8k
Avg merge
1d 8h
Merged PRs (30d)
91

Description

### 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

See example: https://material.angular.io/components/chips/examples#chips-autocomplete

In this example, after selecting an autocomplete option, we want to create a new chip and clear the typed text in the input element. The input is bound to a FormControl instance, so it should be possible to clear the input by simply calling `this.fruitCtrl.setValue(null)` or `this.fruitCtrl.setValue('')`. Instead, the previously typed text remains visible, but if you subscribe to the `FormControl.valueChanges` property you will see the new empty value emitted correctly.

The example works around this issue by accessing the native input element and updating the value directly.

### Reproduction

Steps to reproduce:
1. See example https://material.angular.io/components/chips/examples#chips-autocomplete
2. Remove the nativeElement reference
3. Input text remains visible despite the FormControl instance correctly emitting the new value, creating an inconsistent state

### Expected Behavior

It should be enough to just update the FormControl to ensure the input element has the correct value set.

### Actual Behavior

The input element is left in an inconsistent state unless the user manually updates the native element's value directly.

### Environment

- Angular: n/a (internal stable version http://go/ng-cli)
- CDK/Material: n/a
- Browser(s): Chrome
- Operating System (e.g. Windows, macOS, Ubuntu): macOS

Contributor guide

Open the contributing guide

Research direction

Start with the chips-autocomplete example linked in the issue and reproduce the behavior using MatAutocomplete with a FormControl. Trace how the control's empty value reaches the input after option selection; done means updating the FormControl alone clears the visible text without direct nativeElement access.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.