ionic-team / ionic-team/ionic-framework
bug: radio group `compareWith` doesn't keep in mind `null` values + it's not used to check for deselection
- 主要语言
- TypeScript
- 星标
- 52.7k
- 派生
- 13.3k
- 平均合并
- 1 天 15 小时
- 30 天内合并 PR
- 51
描述
### Prerequisites
- [x] I have read the [Contributing Guidelines](https://github.com/ionic-team/ionic-framework/blob/main/docs/CONTRIBUTING.md#creating-an-issue).
- [x] I agree to follow the [Code of Conduct](https://ionicframework.com/code-of-conduct).
- [x] I have searched for [existing issues](https://github.com/ionic-team/ionic-framework/issues) that already report this problem, without success.
### Ionic Framework Version
v8.x
### Current Behavior
Using `compareWith` with a property name leads to errors being thrown when the value is `null`, which can happen in forms when there is no value yet, or when the value is being cleared. This is because the check is:
```
} else if (typeof compareWith === 'string') {
return currentValue[compareWith] === compareValue[compareWith];
```
If we then want to use `allowEmptySelection` on a radio group, it doesn't work initially, because it doesn't use the `compareWith` to see if the radio button should be unchecked and as the values are not equal by reference, it selects it again instead.
### Expected Behavior
`compareWith` must keep in mind `null` values, as these are valid values in forms, meaning the value is explicitly empty, because `undefined` is used for something else by Angular.
`allowEmptySelection` must use the `compareWith` to check if the selected radio button must be deselected, otherwise it doesn't work if the current value and the value of the radio button isn't equal in reference but equal by `compareWith` property name.
### Steps to Reproduce
1. Go to the [reproduction](https://stackblitz.com/edit/nzwodvxm?file=src%2Fapp%2Fexample.component.ts)
2. Wait for the application to load and see the list of foods, with the currently selected value added in the view.
3. Click the currently selected radio button and see that it's still checked.
I couldn't find the console in Stackblitz, but when the current value is `null`, you'll get an error there.
### Code Reproduction URL
https://stackblitz.com/edit/nzwodvxm?file=src%2Fapp%2Fexample.component.ts
### Ionic Info
```
[WARN] You are not in an Ionic project directory. Project context may be missing.
Ionic:
Ionic CLI : 5.4.16
Utility:
cordova-res : not installed
native-run : not installed
System:
NodeJS : v20.19.1
npm : 10.8.2
OS : macOS Unknown
```
I believe our setup is not following standards? There is cordova and ionic through Angular in the repo...
### Additional Information
_No response_
贡献指南
调研方向
Start with the compareWith logic shown in the issue and the linked StackBlitz reproduction. Done means null values no longer throw and allowEmptySelection deselects a radio when the values match through compareWith; the issue names no repository files or tests to run.
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- angular, typescript
- 领域
- frontend
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100