angular / angular/components

Add 'compareWith' option to mat-radio-group just like mat-select

未关闭
#10,495 17 条评论 36 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

area: material/radio feature help wanted P4
主要语言
TypeScript
星标
25k
派生
6.8k
平均合并
1 天 8 小时
30 天内合并 PR
91

描述

Bug, feature request, or proposal:

Feature request: There is an issue with the mat-radio-group. If you use an object as the value for the form control the corresponding radio button is not checked. It only uses reference based comparison for checking which button should be highlighted.

I would like the ability to specify a comparison method to use while the mat-radio-group is deciding which item is selected. Just like how you can already specify a 'compareWith' method for a mat-select control.

What is the expected behavior?

If you use basic values it works as expected. Example here. In this case the value is set to 1.1 and the 'one,one' button is selected.

What is the current behavior?

However when you use an array, it does not work. Example here. In this case the value is set to [1,1] and none of the buttons are selected. Even though the form control's value is clearly shown to be [1,1].

What is the use-case or motivation for changing an existing behavior?

I am currently trying to dynamically generate a form based on some data given back from an API. The api gives me choices and a selected value to show by default.

{ tag: 'radio button', value: '[0,1]', choices: [ { tag: 'option 1', value: [0,0] }, { tag: 'option 2', value: [0,1] } ] }

In the spec for mat-radio-group and mat-radio-button the value is of type any. So it should support any type of value I want to use.

The current mat-select control already possesses this feature and I would like to see it paralleled in the radio button control. Here is an example of the select control with the 'compareWith' attribute. As you can see it selects the "one,one" value by default.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular: 5.2.6
@angular/material: 5.2.3
typescript: 2.4.2

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先比较 mat-radio-group 和 mat-select 的实现及其相关 spec,使用链接的 StackBlitz 示例重现对象值和数组值的选择。完成标准是 mat-radio-group 支持用于选择值的可配置 compareWith 方法,并且该行为由 radio-group 和 radio-button 的 spec 覆盖。

由索引模型根据 Issue 内容生成。

评估

技术栈
angular, typescript
领域
frontend
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。