angular / angular/components

Radio Button with object as value uncheckes on reset/setvalue/patchvalue

Đang mở
#13,432 13 bình luận 1 reaction 0 người được giao Xem trên GitHub
area: material/radio 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?
Just read the next part it will become obvious.

#### What is the current behavior?
When using objects as the value for MatRadioGroup and MatRadioButton the current implementation lacks a `compareWith` property like the current implementation of MatSelect. Normally the radio button will only do a reference based comparison of the value compared to the radio groups value to see if a button should be checked. This is an issue because I am using an API to get the values for the radio group and buttons this interferes with this way of doing a comparison.

However MatRadioButton does have a property called `checked` which I can use. I wrote my own compare method and have it check the current value of the MatRadioGroup with the current value of the MatRadioButton and return true to set the `checked` state of the radio button.

When I use `reset(value)`, `setValue(value)`, or `patchValue(value)` or click on a radio to change the value of the MatRadioGroup, everything works. However performing this twice with the same object results in the radio being unchecked.

#### What are the steps to reproduce?
https://stackblitz.com/edit/angular-material-radio-not-checked-bug

Press the set button twice.
OR
Press the set button then press the reset button twice
OR
Change the selected radio by clicking on a new option and then press the reset button twice
OR
Do not change anything and right away (after a fresh page load) press the reset button

#### What is the use-case or motivation for changing an existing behavior?
Allowing me to use objects or arrays with MatRadioGroup/MatRadioButton while preserving the functionality of a simple reset button for my form.

#### Which versions of Angular, Material, OS, TypeScript, browsers are affected?
material 5 and 6

#### Is there anything else we should know?
This may be related to:
https://github.com/angular/material2/issues/11368

I also think that this feature request would also help potentially fix this issue depending on implementation:
https://github.com/angular/material2/issues/10495

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

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

Hướng nghiên cứu

Bắt đầu với bản tái hiện StackBlitz được liên kết và kiểm tra cách xử lý value/checked trong MatRadioGroup và MatRadioButton. Tái hiện các lệnh gọi lặp lại đến reset, setValue và patchValue với các giá trị đối tượng, sau đó theo dõi cách lần cập nhật thứ hai được so sánh. Hoàn tất khi radio được chọn vẫn được đánh dấu sau mỗi lần cập nhật lặp lại và sau khi thay đổi các tùy chọn.

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
35/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.