angular / angular/components

mat-chip with autocomplete can add unwanted chips

Đang mở
#13,574 12 bình luận 15 reaction 0 người được giao Xem trên GitHub
area: material/autocomplete area: material/chips P4
Ngôn ngữ chính
TypeScript
Star
25k
Fork
6.8k
Merge trung bình
1 ngày 8 giờ
Pull request đã merge (30 ngày)
91

Mô tả

#### Bug, feature request, or proposal:
Bug

#### What is the expected behavior?
Typing a partial search term, using arrow keys to highlight option on autocomplete list, and pressing Enter should add only the selected chip.

#### What is the current behavior?
Intermittently, two chips are added. One for the selected value and one with the partial search term.

#### What are the steps to reproduce?
Providing a StackBlitz reproduction is the *best* way to share your issue.

StackBlitz starter: https://goo.gl/wwnhMV

I tried creating a StackBlitz to reproduce it, but couldn't get it to reproduce. Then I realized that it's a race condition causing it. More below...

#### What is the use-case or motivation for changing an existing behavior?
Addtional chip is unexpected behavior

#### Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Angular/Material >= v6 for sure.

#### Is there anything else we should know?
The problem happens depending on the order that event handlers get executed. The code from the [official example](https://stackblitz.com/angular/klblpljogjd) expects the optionSelected event of the mat-autocomplete to execute first (which clears out the input box), then for the matChipInputTokenEnd event of the input to execute (which avoids adding a chip if it's blank).

For whatever reason, using the exact same code and framework version in my app, the event handlers execute in the opposite order. Since the input hasn't been cleared yet, the search term gets added as an unexpected chip. Then the option from the autocomplete gets added as the expected chip.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Start with the official Angular Material autocomplete and chips example, then trace the matChipInputTokenEnd and optionSelected event handlers and their execution order. Reproduce the race on Angular/Material v6 or later and verify that pressing Enter after selecting an option adds only the selected chip, not the partial search term.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
angular, typescript
Lĩnh vực
frontend
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.