Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I try in Angular 15 to change the border of mat-chip inside mat-form-field in case of invalid data to red like it was in mat-form-field without mat-chip-row
My code works fine.
My problem is on hover I can't fixed it out.
If someone can help I appreciate it?

What I have tried:

My code is like that:
HTML
<mat-form-field #eventForm appearance="outline" floatLabel="always" [ngClass]="{'textFieldInvalid': profileForm.controls['eventSelected'].invalid}" style="font-size: 1em; width: 100%;">
    <mat-label> event </mat-label>
    <mat-chip-grid #chipGridevent aria-label="add event">
      <mat-chip-row *ngFor="let eventOp of profileForm.get('eventListSelected')?.value"
                    (removed)="removeevent(eventOp)">
        {{eventOp.name}}
        <button matChipRemove [attr.aria-label]="'remove ' + eventOp.name">
          <mat-icon>cancel</mat-icon>
        </button>
      </mat-chip-row>
      <input placeholder="add event"
            #eventInput
            formControlName="eventSelected"
             [matChipInputFor]="chipGridevent"
             [matChipInputSeparatorKeyCodes]="separatorKeysCodes"
             [matAutocomplete]="autoevent"
             [matChipInputAddOnBlur]="addOnBlur"/>
            </mat-chip-grid>
    <mat-autocomplete #autoevent="matAutocomplete" [displayWith]="displayeventFn" (optionSelected)="eventSelected($event)">
      <mat-option *ngFor="let eventOp of eventFiltered | async" [value]="eventOp">
        {{eventOp.name}}
      </mat-option>             
    </mat-autocomplete> 
  </mat-form-field>


my scss:
CSS
::ng-deep [dir=rtl] .textFieldInvalid  .mat-mdc-text-field-wrapper .mdc-notched-outline__leading {
  border-color: red;
}

::ng-deep.mat-mdc-form-field:hover .textFieldInvalid  .mat-mdc-text-field-wrapper .mdc-notched-outline__leading {
  background-color: red;
}

::ng-deep [dir=rtl]  .textFieldInvalid  .mdc-text-field .mdc-notched-outline__trailing, 
.mdc-notched-outline__trailing[dir=rtl] .mdc-floating-label{
  border-color: red;
}

::ng-deep [dir=rtl]  .textFieldInvalid .mat-mdc-text-field-wrapper .mdc-notched-outline__notch {
  border-color: red;
}

::ng-deep [dir=rtl]  .textFieldInvalid .mdc-text-field--outlined .mdc-notched-outline--upgraded .mdc-floating-label--float-above{
  color: red;
}

::ng-deep [dir=rtl] .mat-form-field:hover .textFieldInvalid .mat-mdc-form-field-outline-thick .mat-mdc-text-field-wrapper .mdc-notched-outline__leading {
  border-color: red;
}
Posted
Updated 2-Jul-23 23:25pm
v2

1 solution

You can add the following to your scss file that will show a border color of red. For testing I also added a background color of red -

::ng-deep [dir=rtl] .textFieldInvalid.mat-mdc-form-field:hover .mat-mdc-text-field-wrapper .mdc-notched-outline__leading,
::ng-deep .textFieldInvalid.mat-mdc-form-field:hover .mat-mdc-text-field-wrapper .mdc-notched-outline__leading {
  border-color: red;
  background-color: red; /* Change the background color on hover */
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900