bug(MatAutocomplete): MatAutocomplete + FormControl does not clear input correctly after option selection
- 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ả
### 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
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu với ví dụ chips-autocomplete được liên kết trong issue và tái hiện hành vi bằng cách sử dụng MatAutocomplete với một FormControl. Theo dõi cách giá trị rỗng của control đến input sau khi chọn một option; hoàn tất khi chỉ cần cập nhật FormControl là có thể xóa văn bản hiển thị mà không truy cập trực tiếp vào nativeElement.
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ó
- 3/5
- Thời gian dự kiến
- 1-2 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
- 35/100