angular / angular/components

bug(material/chip): textContent of any HTML element inside mat-chip-row is being appended to FormControl value on focus out (blur) event

オープン
#27,839 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
area: material/chips P3
主要言語
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

### Description

When there is any HTML element inside ``, or even just the matChipRemove button is wrapped inside some `` (like with `*ngIf`, checking if the user has the privilege to delete), then the whole chip-row's value contains this element's textContent (button with `cancel` in this case) after focusing out of the component.

So for example, value `["Apple"]` becomes `["Apple cancel"]` (because `cancel` is part of ``'s textContent).

```

{{ fruit }}


cancel

```

(when `matChipRemove` button is not wrapped inside `` or any other HTML element then its textContent is being ignored, which, I guess, is correct behavior)

### Reproduction

StackBlitz link:
https://stackblitz.com/edit/ovb2sn-s41kjs?file=src%2Fapp%2Fchips-autocomplete-example.html,src%2Fapp%2Fchips-autocomplete-example.ts

Steps to reproduce:
Click on the text input and then focus it out.
This will run Material's blur/focusOut code and update the form control value with the chips' textContent which becomes `["Apple cancel"]`.
More focus in/out clicks will keep appending ` cancel` to the form control's value.

### Expected Behavior

Not appending HTML elements' textContent to chip's form control value

### Actual Behavior

HTML element's textContent is being appended to chip's form control value

### Environment

- Angular: 15+
- CDK/Material: 15+
- Browser(s): Any browser
- Operating System (e.g. Windows, macOS, Ubuntu): Any OS

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

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

調査の方向性

再現ファイル src/app/chips-autocomplete-example.html と src/app/chips-autocomplete-example.ts から始め、issue に記載されている Material の blur/focusOut の動作を追ってください。フォーカスを外しても、ネストされた HTML の textContent が chip form-control の値に追加されないことを、matChipRemove が ng-container でラップされている場合も含めて確認してください。

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

評価

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

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

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