angular / angular/components

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

オープン
#25,809 コメント 4 件 リアクション 5 件 担当者 0 名 GitHub で見る
area: material/input P3
主要言語
TypeScript
スター
25k
フォーク
6.8k
平均マージ
1日 8時間
マージ済み PR(30日)
91

説明

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

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

issue にリンクされている chips-autocomplete の例から始め、MatAutocomplete と FormControl を使って動作を再現します。オプション選択後にコントロールの空の値がどのように入力欄へ到達するかを追跡します。FormControl だけを更新することで、nativeElement に直接アクセスせずに表示テキストがクリアされれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
angular, typescript
領域
frontend
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。