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.

help(mat-radio-button): I can't use `color` attribute in the <mat-radio-button>

See original GitHub issue

What are you trying to do?

<mat-radio-group aria-label="Select an option">
  <mat-radio-button value="1" color="primary">Option 1</mat-radio-button>
  <mat-radio-button value="2" color="accent">Option 2</mat-radio-button>
  <mat-radio-button value="3" color="warn">Option 3</mat-radio-button>
  <mat-radio-button value="4" color="info">Option 4</mat-radio-button>
</mat-radio-group>

I want to create a custom material theme and use info theme palette like below. <mat-radio-button value="4" color="info">Option 4</mat-radio-button>

What troubleshooting steps have you tried?

For the other components like button, toggle, checkbox, I can use color=“info” palette.

<mat-radio-button value="4" color="info">Option 4</mat-radio-button>

I expect mat-info class in the <mat-radio-button>, but not working 😦

<mat-radio-button _ngcontent-csm-c296="" class="mat-radio-button example-radio-button mat-radio-checked" ng-reflect-value="Winter" id="mat-radio-2">
 ...
 ...
</mat-radio-button>

Reproduction

Steps to reproduce: https://material.angular.io/components/radio/examples you can add color=“info” in the <mat-radio-button>

<mat-radio-group aria-label="Select an option">
  <mat-radio-button value="1" color="primary">Option 1</mat-radio-button>
  <mat-radio-button value="2" color="accent">Option 2</mat-radio-button>
  <mat-radio-button value="3" color="warn">Option 3</mat-radio-button>
  <mat-radio-button value="4" color="info">Option 4</mat-radio-button>
</mat-radio-group>

Environment

  • Angular: v13
  • CDK/Material: v13
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
crisbetocommented, Jan 26, 2022

These palettes aren’t in the Material Design specification which we need to adhere to though. Also there’s nothing stopping you from defining your own color directive that accepts any color:

@Directive({
  selector: '[color]'
})
class ColorDirective {
  @Input()
  set color(value: string) {
    if (this._color) {
      this._elementRef.nativeElement.classList.remove(`mat-${this._color}`);
    }

    this._color = value;
    this._elementRef.nativeElement.classList.add(`mat-${value}`);
  }
  private _color: string;

  constructor(private _elementRef: ElementRef<HTMLElement>) {}
}
1reaction
Totaticommented, Jan 24, 2022

Duplicate of #11888

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to change color of radio button in angular material 2
I'm trying to change the color of the angular material 2 radio button on PROPER way, without overriding css. By default, it uses...
Read more >
Radio button | Angular Material
<mat-radio-button> provides the same functionality as a native <input ... The default color for radio buttons can be configured globally using the ...
Read more >
<mat-radio-button> in Angular Material - GeeksforGeeks
If we want to change the theme then we can change it by using the color property. In angular we have 3 themes,...
Read more >
mat-radio-button, Angular material radio button Usage, Example
We can control the label position using labelPosition property of <mat-radio-button> . · If you want assign some default value to radio group...
Read more >
Angular Radio button, Angular Material radio button ... - Edupala
We can configure the default color for the angular mat-radio-group component in the provider option using MAT_RADIO_DEFAULT_OPTIONS and we can assign material ...
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