Customize the focus color of mat-label within a mat-form-field in Angular

Within my mat-form-field, I have a mat-chip-list set up similar to the example provided in this link. When I click inside the field, the mat-label and what appears to be the border-bottom (not entirely sure) change color when focused. How can I customize these colors? Currently, they reflect the default angular theme color, but I want to make some changes.

<mat-form-field class="example-chip-list" appearance="fill">
  <mat-label>Favorite Fruits</mat-label>
  <mat-chip-list #chipList aria-label="Fruit selection">
    <mat-chip *ngFor="let fruit of fruits" (removed)="remove(fruit)">
      {{fruit.name}}
      <button matChipRemove>
        <mat-icon>cancel</mat-icon>
      </button>
    </mat-chip>
    <input placeholder="New fruit..."
           [matChipInputFor]="chipList"
           [matChipInputSeparatorKeyCodes]="separatorKeysCodes"
           [matChipInputAddOnBlur]="addOnBlur"
           (matChipInputTokenEnd)="add($event)">
  </mat-chip-list>
</mat-form-field>

I attempted the following code without success:

mat-label:focus{
color: red
}

I came across this solution: Change color of matInput, but I prefer not to use "!important".

Answer №1

To update the color of a mat component without relying on ::ng-deep or !important, you can add the CSS to a global style sheet.

For example, in your scenario:

.mat-focused .mat-form-field-label {
  /*change color of label*/
  color: red;
 }

If you're unsure how to create a global stylesheet, check out this resource:

For further information, take a look at: https://material.angular.io/guide/customizing-component-styles

It's worth noting that ::ng-deep is deprecated, so it's recommended to utilize global stylesheets instead of ::ng-deep.

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

Highlighting the selected tab with an active class

Currently in the process of learning angularJs, I am still new to it and attempting to dynamically add an active class to the recently clicked tab. Within my interface, there are four tabs: insert, view, update & delete. My goal is to apply the active ...

The initial website design only occupies half of the webpage with HTML

My code is only filling up half the screen, specifically the left half but not the right. I attempted to set the html height and width to 100%, but unfortunately, it did not resolve the issue. Additionally, after this adjustment, I encountered problems wit ...

The overlay background is being obscured by surrounding elements

Hey there! I'm experimenting with some basic coding and ran into an issue with an overlay. Here's the site link: Sorry for the strange language. :-) If you click on the button with the tiny icon, you'll notice that the overlay form isn&apos ...

Using ngModel to Enhance Ionic Forms

I've encountered an issue with mapping a form to a model object. Once I include [[ngModel]] in the ion-input, the page fails to load without any errors. html <ion-input type="text" [(ngModel)]="personModel.username" formControlName="username" id= ...

Is it possible to reference the same PHP file in multiple locations?

Currently, I am working on a web development project where I have created a header.html file to store the common header for all my webpages. This header file is located in the parent directory. Within my header.html file, I have included references to bot ...

Looking to enhance the accessibility of a dynamically generated file by implementing the ability to expand and collapse sections as parent nodes

Currently working on a webpage where I am showcasing a testsuite file as the parent node and test cases within the testsuite file as child nodes. I have added checkboxes to both the parent and child nodes. Now, my goal is to include an ex ...

Display the Bootstrap dropdown menu on the right-hand side

I am currently working on a dropdown menu and I would like the dropdown items to be displayed on the right side. The functionality is working, but there seems to be an issue where the dropdown menu is not fully visible. The dropdown menu is located within ...

What is the best way to align an image to flex-end?

I recently started using React and ran into issues trying to align my image using CSS. Despite trying various methods like justifyContent, justifySelf, and floating right, I couldn't get the image to align on the right side of the screen without resor ...

Display a loading message before fetching remote data in the Bootstrap modal box

Here is the code I am using to load remote PHP data into a Bootstrap modal box: $(function() { $(window).bind("resize", function() { if ($(this).width() < 400) { $('#tabs-content').removeClass('col-xs-10').ad ...

Is it feasible to capture a screenshot of a URL by using html2canvas?

Is it possible to take a screenshot of a specific URL using html2canvas? For example, if I have the following URLs: mydomain.com/home mydomain.com/home?id=2 mydomain.com/home/2 How can I capture and display the screenshot image on another page? window ...

Accessing node modules in the index.html file located in the public directory

Is there a way to access node_modules, such as Angular, from my index.html file? This is the current file structure: node_modules public jsfolder cssfolder index.html server.js I am aware that this code snippet does not work in index.html: <scri ...

Sending fillable PDF form by email upon submission

I need to send the entire PDF document, not just the filled fields, to a specific email address when a user submits a fillable form. Previous discussions have debated whether this is possible or not, and the answer is confirmed as YES. Now I am wondering ...

Get your columns in order with Bootstrap4

I need to rearrange my 3 columns on desktop and mobile devices in different ways. Currently, my grid structure is set up like this: <div class="row"> <div class="col-xs-3 col-md-6"> 1 </div> <div class="col-xs-3 col-md- ...

Creating a personalized directive in Angular 2 that restricts input to only characters that adhere to a specified regular expression

I have successfully developed a directive that restricts any character from being typed in an input field if it does not match a specified pattern. import { Directive, Input, Output, HostListener, EventEmitter } from "@angular/core" @Directive({ select ...

How to require 2 out of 4 input fields in Angular using typescript

exploring the intricacies of design decisions, sub systems, frameworks, and libraries Hello! I am relatively new to Angular and have encountered a puzzling issue that I can't quite figure out. I could easily create a lengthy if statement to address i ...

Adding a background color to the body of your PHP and HTML email template is a simple way to enhance

I am currently using a confirmation email template with a white background, but I want to change it to gray. However, I'm unsure how to update the PHP file containing the email function below: $headers = "From: " . stripslashes_deep( html_entity_deco ...

Unpacking Constructor with visible arguments

In my constructor, I utilize destructuring to simplify the parameters needed to create an object with default values. export class PageConfig { constructor({ isSliding = false }: { isSliding?: boolean; getList: (pagingInfo: PagingInfo) =&g ...

dividing a solitary string (plain text only, no HTML) evenly among three separate div containers

Recently, I encountered a frustrating dilemma. I'm trying to split a string between three divs, but they are not equal in height, so I can't divide the string based on character count. To illustrate the issue, I've created a small sketch. ...

Is there a way in Javascript to save the inner HTML of an element in a cache so that it can be re-rendered after the page is refreshed

Is there a way to cache part of a webpage on the client side using JavaScript/jQuery? Does this method have any limitations in terms of the amount of data that can be cached? How can I access this cache after refreshing the page in order to re-render it? ...

Avoid the sudden change in page content when using Router.Navigate

When the link below is clicked, the current page jumps to the top before proceeding to the next page. <a href="javascript:void(0);" (click)="goToTicket(x.refNo, $event)">{{x.ticketTitle}}</a> component.ts goToTicket(refNo, e) { e.prev ...