How Can I customize mat-form-field in disabled state
Asked Answered
H

6

6

I am trying to customize the angular material mat-form-field : I was able to customize the underline border using :

::ng-deep.mat-form-field-ripple {
  background-color: yellow;
}

now I am trying to customize the underline border in the disabled state to be solid instead of the dashed line :

I tried this but it didn't work for underline :

::ng-deep.mat-form-field-disabled
 {

 }

enter image description here

I want this to be gray solid in disabled state

 <mat-form-field>
    <input matInput placeholder="Input" [disabled]='true'>
  </mat-form-field>
Hammers answered 24/1, 2019 at 21:56 Comment(2)
Hi, how did you solve that?Joappa
Try this : https://mcmap.net/q/1664138/-how-can-i-customize-mat-form-field-in-disabled-stateHammers
H
9

This Fixed it :

 ::ng-deep.mat-form-field-disabled .mat-form-field-underline 
    { 
    background-image: linear-gradient( to right, rgba(0, 0, 0, 1) 0, rgba(0, 0, 0, 0.42) 33%, #c2c7cc 0 ) !important; 
    background-size: 1px 100% !important;
     background-repeat: repeat-x !important; 
    } 
Hammers answered 30/4, 2019 at 0:37 Comment(1)
ng-deep is deprecated :') #47024736Malvie
H
1

You need to target the following class:-

.mat-form-field-disabled .mat-form-field-underline

The css you will be looking to change is:-

background-image: linear-gradient(to right,rgba(0,0,0,1) 0,rgba(0,0,0,.42) 33%,transparent 0);
background-size: 4px 100%;
background-repeat: repeat-x;

So you can either unset: all and start from fresh or update the background-size: 1px 100%; or whatever suits your needs

Hexagon answered 24/1, 2019 at 22:13 Comment(5)
I tried it didn't work --> ::ng-deep.mat-form-field-disabled.mat-form-field-underline { background-image: linear-gradient( to right, rgba(0, 0, 0, 1) 0, rgba(0, 0, 0, 0.42) 33%, transparent 0 ); background-size: 4px 100%; background-repeat: repeat-x; }Hammers
Add it to your style.css without the ng-deep and you need to change the background-size. Also try adding !important.Hexagon
Didn't work ---> .mat-form-field-disabled.mat-form-field-underline { background-image: linear-gradient( to right, rgba(0, 0, 0, 1) 0, rgba(0, 0, 0, 0.42) 33%, transparent 0 ) !important; background-size: 4px 100% !important; background-repeat: repeat-x !important; }Hammers
Your background size is still 4px, also add a space between the classes.Hexagon
This worked --> ::ng-deep.mat-form-field-disabled .mat-form-field-underline { background-image: linear-gradient( to right, rgba(0, 0, 0, 1) 0, rgba(0, 0, 0, 0.42) 33%, #c2c7cc 0 ) !important; background-size: 1px 100% !important; background-repeat: repeat-x !important; }Hammers
M
1

You can try

::ng-deep .mat-form-field-disabled {
   .mat-input-element {
        color: rgba(0, 0, 0, 0.14);
    }
    .mat-form-field-label {
        color: rgba(0, 0, 0, 0.14);
    }
    .mat-form-field-underline {
         color: rgba(0, 0, 0, 0.14);
    }
    .mat-form-field-ripple {
         color: rgba(0, 0, 0, 0.14);
    }
    .mat-form-field-required-marker {
         color: rgba(0, 0, 0, 0.14);
    }
Middlebrooks answered 19/1, 2021 at 8:26 Comment(0)
H
0

This fixed it :

    ::ng-deep.mat-form-field-disabled .mat-form-field-underline {
    background-image: linear-gradient(
    to right,
    rgba(0, 0, 0, 1) 0,
    rgba(0, 0, 0, 0.42) 33%,
    #c2c7cc 0
  ) !important;
  background-size: 1px 100% !important;
  background-repeat: repeat-x !important;
}
Hammers answered 25/1, 2019 at 0:43 Comment(0)
L
0

You don´t need linear gradient in background-image. This worked for me:

::ng-deep .mat-form-field-disabled .mat-form-field-underline {
  background-color: #949494 !important;
  background-size: 1px 100% !important;
  background-repeat: repeat-x !important;
}
Laureate answered 11/2, 2022 at 15:21 Comment(0)
B
0
::ng-deep .mat-form-field-appearance-outline.mat-form-field-disabled .mat-form-field-outline,
    .mat-input-element:disabled {
        color: red;

    }

this did the job for me, to color the text and the borders.

Beaut answered 15/7, 2022 at 9:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.