bug([MatChipInput]): matChipInputAddOnBlur: true + selecting option by click inserts 2 chips
- 主要言語
- TypeScript
- スター
- 25k
- フォーク
- 6.8k
- 平均マージ
- 1日 8時間
- マージ済み PR(30日)
- 91
説明
### Description
This is an intentional duplicate of https://github.com/angular/components/issues/19279, because it's been closed with a workaround that no longer works with the new Angular Material components (v15+).
The workaround was to set `matChipInputAddOnBlur` to `false` and handle the `(blur)` event on our own while ignoring the one that is related (`relatedTarget`) to `mat-option` element, however, now, clicking the `mat-option` will fire the `FocusEvent` with `relatedTarget: null`.
My updated (and working) workaround looks like this:
```
addOnBlur(event: FocusEvent) {
const target: HTMLElement = event.relatedTarget as HTMLElement;
if (!target) {
return;
}
this.addCustomChip(this.itemInput.nativeElement.value); // or manually create MatChipInputEvent etc...
}
```
However, the original issue is still there and it shouldn't require any workaround in the first place.
### Reproduction
https://stackblitz.com/edit/angular-rd38q1-b74xmz?file=src%2Fapp%2Fchips-autocomplete-example.ts,package.json,src%2Fapp%2Fchips-autocomplete-example.html,src%2Fmain.ts

### Expected Behavior
Only the selected option should become a chip
### Actual Behavior
The input text also becomes a chip
### Environment
- Angular: v15+
- CDK/Material: v15+
- Browser(s): Chrome
- Operating System (e.g. Windows, macOS, Ubuntu): Windows
コントリビューションガイド
調査の方向性
リンクされている StackBlitz の再現コードから始め、特に src/app/chips-autocomplete-example.ts、src/app/chips-autocomplete-example.html、package.json を確認し、Chrome でクリックによる選択フローを再現します。mat-option を選択したときにそのオプションだけが chip として追加され、入力テキストも追加されなければ作業完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- angular, typescript
- 領域
- frontend
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 55/100