question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:31
  • Comments:16 (2 by maintainers)

github_iconTop GitHub Comments

14reactions
SC-JCcommented, Mar 17, 2020

Any update on this, seems like a rather basic core feature for any value accessor where you can pass objects as values.

9reactions
keatkeat87commented, Mar 25, 2018

sometime, we change the select to radio group is just because of user experience. user want to see all selection all the time. so i think compare With is a necessary feature.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add 'compareWith' option to mat-radio-group just like mat-select
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...
Read more >
mat-select calls compareWith only on mouseover button
I have a strange behavior with a simple mat-select . <mat-select [compareWith]="compareFn" placeholder="Options" formControlName="options" ...
Read more >
Using compareWith in Angular Material 2 multiple-select ...
Recently I needed to implement setting some objects as selected per default in the mat-select multiple-choice input options. The user should see the...
Read more >
Select | Angular Material
<mat-select> is a form control for selecting a value from a set of options ... To add options to the select, add <mat-option>...
Read more >
mat-radio-button, Angular material radio button Usage, Example
mat-radio-button selector is an Angular material radio box component. ... <mat-radio-group aria-label="Select an option"> <mat-radio-button value="1">Option ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found