Tips on updating the outer ripple color of radio buttons in Angular 6 Material

I was trying to customize the default color of Angular Material Radio buttons. I managed to change the radio button color successfully.

<mat-radio-group>
  <mat-radio-button value="1">Option 1</mat-radio-button>
  <mat-radio-button value="2">Option 2</mat-radio-button>
</mat-radio-group>

However, I encountered an issue where I couldn't modify the outer ripple effect color when clicking on an option. Can someone please assist me in resolving this problem?

https://i.sstatic.net/BCmlb.png

Answer №1

Check out this solution for customizing the styling of mat-radio buttons

  ::ng-deep .mat-radio-button.mat-accent .mat-radio-ripple .mat-ripple-element {
        opacity: 0.5 !important;     /*change color on click event*/
        background-color: blue !important;
  }

  ::ng-deep .mat-radio-button.mat-accent .mat-radio-inner-circle {
        background-color: blue!important;   /*customize inner circle color*/
  }

  ::ng-deep.mat-radio-button.mat-accent.mat-radio-checked .mat-radio-outer-circle {
       border-color:blue!important; /*adjust outer ring color*/
  }

I hope you find this helpful.

Answer №2

In order to personalize Angular material, one must override the existing CSS rules. To achieve this for radio buttons, you can customize the ripple effect by changing the following rules:

.mat-radio-button.mat-accent .mat-radio-ripple .mat-ripple-element {
     background-color: rgba(0, 0, 0, .1) !important;
 }

Answer №3

To match the brown theme on a white background, I had to make some adjustments. The inner and outer circles needed to be brown when selected and only the outer circle brown when not selected. Additionally, I wanted the ripple effect to blend in seamlessly. After some tweaking, here is the solution that worked:

  & .mat-radio-button.mat-accent .mat-radio-ripple .mat-ripple-element {
    background-color: brown !important; // Override material
  }

  & .mat-radio-button.mat-accent .mat-radio-inner-circle {
    background-color: brown !important; // Override material
    z-index: 3;
  }

  & .mat-radio-button .mat-radio-outer-circle {
    border-color: brown !important; // Override material
    z-index: 3;
  }

No changes in opacity were necessary.

Answer №4

Here is a snippet from my code:

// Styling with CSS
:host ::ng-deep .mat-radio-button.mat-mycolor.mat-radio-checked .mat-radio-outer-circle {
  border-color: blue !important;
}

:host ::ng-deep .mat-radio-button.mat-mycolor .mat-radio-inner-circle {
  background-color: blue !important;
}

:host ::ng-deep .mat-radio-button.mat-mycolor .mat-ripple-element {
  background-color: blue !important;
}

// Including HTML template
<mat-radio-group [(ngModel)]="selectedAction">
  <mat-radio-button [color]="radioColor" [style.color]="textColor" [value]="action" *ngFor="let action of actions">{{action}}</mat-radio-button>
</mat-radio-group>  

// TypeScript logic
textColor: string = "#ff0000";
radioColor: string = "mycolor";
actions: string[] = ["Take a walk", "Mow the lawn"];
selectedAction: string = this.actions[0];

Answer №5

To alter the color of the mat radio button, simply add the code snippet below to your module file.

If you wish to change the default color of radio buttons across your application, you can do so by globally configuring the MAT_RADIO_DEFAULT_OPTIONS provider.

Example code:

providers: [{ provide: MAT_RADIO_DEFAULT_OPTIONS, useValue: { color: 'primary' }, }]

Answer №6

This solution did the trick for me

    ::ng-deep .mat-mdc-radio-button .mdc-radio .mdc-radio__native-control:enabled:checked+.mdc-radio__background .mdc-radio__outer-circle  {
      border-color: #353535 !important;
    }
    
    ::ng-deep .mat-mdc-radio-button .mdc-radio .mdc-radio__native-control:enabled+.mdc-radio__background .mdc-radio__inner-circle {
      border-color: #585858 !important;
    }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Generate an additional CSS animation to display before the next page is loaded

When loading a page, I am implementing CSS transitions to display animated lines. To activate these lines, I am utilizing a jQuery script to change the class on the line elements. I am looking to reverse the CSS transitions when transitioning to the next ...

Personalize the design of the mat-calendar by eliminating the month label

I'm attempting to remove the month label from an angular material mat-calendar component. You can check out my issue on StackBlitz by following this link: https://stackblitz.com/edit/am-all-imports-mviy6e?file=styles.scss <mat-calendar [dateClass ...

How to format decimals in Typescript/Angular with a pipe: comma or dot?

I've recently developed a custom pipe and I'm looking to enhance it by adding commas or periods to thousands values. For instance, 1000 should be displayed as either 1,000 or 1.000. Here is the code snippet for my custom pipe: import { Pipe, Pi ...

Challenges encountered while developing Angular FormArrays: Managing value changes, applying validators, and resolving checkbox deselection

I am facing an issue with my Angular formArray of checkboxes. In order to ensure that at least one checkbox is selected, I have implemented a validator. However, there are two problems that I need to address: Firstly, when the last checkbox is selecte ...

Trouble with Bootstrap columns displaying on smaller devices

I designed a grid with 3 columns that exhibits issues, specifically that the columns shrink too much on smaller screens and distort the content. Is there a way to introduce a break-point at around 1000px so that all content shifts into a single column? An ...

Exploring Angular 8: Leveraging the power of HttpClient.get.toPromise

Within a service constructor, I am attempting to asynchronously call 2 HttpClient.get requests. My goal is for both get requests to be completed by the time the constructor finishes executing. public async ReadConfiguration () { await this.http.get ...

Efficiently configuring Angular 2 with ng-bootstrap

Hi there, I am currently diving into the world of Angular and Bootstrap, while also exploring node js. My goal is to create a solid foundation using the webpack starter kit available at this link: https://github.com/AngularClass/angular2-webpack-starter ...

The alignment of my card icons changes depending on the size of the paragraph

Here are my cards I am attempting to give them a relative position and the parent div an absolute position, but it is not working as expected. Despite several attempts, I still cannot get the desired result of positioning the cards correctly within the p ...

"Exclusive Mui sx styles will be applied only when a specific breakpoint

As I update my old mui styling to utilize the sx attribute, I've noticed the ability to specify styles for different breakpoints using sx = {{ someCssProp: { xs: ..., md: ... and so on. Prior to this, I had been using theme.breakpoints.only for some ...

In Ionic 2, any modifications made to the data model will only be reflected in the user interface after there is

Q) Why does my data seem to magically appear on the UI after interacting with it, even though I have made changes in the backend? For instance, when fetching and updating data bound to a list, such as: this._LocalStorageService.getClients().then( (data ...

Adjusting the width of row items in Angular by modifying the CSS styles

I am envisioning a horizontal bar with items that are all the same width and evenly spaced apart. They can expand vertically as needed. Check out the updated version here on StackBlitz https://i.sstatic.net/MFfXd.png Issue: I am struggling to automatica ...

Leveraging CSS nth-child selector in conjunction with ngFor in angular2

Looking for a way to style odd and even rows differently in my dynamically generated table using ngFor directive in angular2. *ngIf="AreThereMyOldMessages" *ngFor="let oldm of MyOldMessages;let i=index" *ngIf="AreThereMyNe ...

Runtime not able to identify new modifications post migration from Angular 2 to Angular 6

I successfully upgraded my Angular 2 project with DotNetCore to Angular 6 by executing the following command: npm install -g npm-check-updates ncu -u After completing the migration process, I found that while I can still run my previously developed proje ...

Protecting NestJS API for Angular App with Auth0

Currently, I am working on an Angular application that utilizes NestJS as the backend. Authentication is functioning properly in the Angular app, where users can log in to Auth0 and are redirected back to our app seamlessly. The /token call in the network ...

Issue with CSS background scaling bug

Is it possible to make the cloud background scale within the box? The current issue can be viewed here: I have tried various methods to resolve the problem where the background scales even beyond the limited box. However, I could not identify the solutio ...

Anomaly in Form Validation with Semantic-UI

This time around, I am implementing Semantic-UI with React. In the past, I have successfully utilized Semantic-UI's form and form validation features in various projects without encountering any issues. However, a new problem has arisen, which I will ...

Make the height of the div the same as the size of the screen

In my Twitter Bootstrap project, I have a div element that contains content which will overflow vertically off the screen. I want the div to adjust its height to match the size of the browser window, allowing the remaining content to scroll vertically wit ...

Having trouble aligning elements in a single line using Bootstrap

I've been experimenting with different methods to align elements on the same line, such as using bootstrap and flexbox. However, I haven't been able to achieve the desired result. The goal is for the elements to stay on the same line even when th ...

Positioning images within a relatively positioned div using absolute positioning

I have come across multiple discussions on this topic, but I am still struggling to make the following code snippet function correctly: .container { position: relative; width: 100%; } .left { position: absolute; left: 0px; } .right { positio ...

Guide on making a JavaScript button with both "light and dark" modes

Currently, I am attempting to change the color scheme of the page by adjusting the :root variables using a function called changeBackgrondColor(). This function is then assigned to the fontAwesome moon "button". However, when I click on the moon, the pag ...