angular / angular/components

bug(material/chip): Mdc Chip Grid empties all options when using Reactive Forms and focusing out

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

説明

### Is this a regression?

- [X] Yes, this behavior used to work in the previous version

### The previous version in which this bug was not present was

14.2.6

### Description

Having Reactive forms attached to `mat-chip-grid` which accepts an array of object values, clears them on focus out.

### Reproduction

Steps to reproduce:
1. Create a formgroup with some formControl
2. Bind it to ` `
3. Add some new options (or the same works if the list is already populated) that are **arrays of objects**.
4. Focus out of the component

https://stackblitz.com/edit/angular-6g9jz1?file=src%2Fapp%2Fchips-input-example.ts,src%2Fapp%2Fchips-input-example.html

Upon further investigation, figured that the core problem is that on focus out, object values are transformed to strings hence why we don't see the name property. Nevertheless objects were not transformed in v 14.

![mat-grid-bug](https://user-images.githubusercontent.com/26407402/210384868-edfda991-132a-48dd-9a44-90aeaeebaebc.gif)

_Note:_ In the Docs Chip list works as expected because it is not bound to Reactive forms

### Expected Behavior

All options remain with previously defined object values

### Actual Behavior

All options are transformed to strings thus we have empty text options

### Environment

- Angular: 15.0.4
- CDK/Material: 15.0.3
- Browser(s): Chrome 108.0.5359.124
- Operating System: macOS Ventura 13.1

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

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

調査の方向性

リンクされた StackBlitz の再現例から始め、特に src/app/chips-input-example.ts と src/app/chips-input-example.html を確認し、mat-chip-grid がオブジェクトの配列を使って Reactive Forms にどのようにバインドされているかを調べます。フォーカスアウト時の挙動を再現し、その後もオプションがオブジェクトの値と表示テキストを保持していることを確認します。

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

評価

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

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

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