Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make mat-checkbox unclickable in Angular material

I can make my mat-checkbox disabled, but want to maintain the same css that it has when being enabled. The checkbox will be checked when its input text has a value, like I did here below:

<mat-checkbox [disableRipple]="true" [checked]="option.controls.text.value !== ''">
  <input #infoBox matInput formControlName="info" class="input-other" maxlength="100" type="text" [value]="option.controls.text.value">
</mat-checkbox>
like image 277
user1019042 Avatar asked Dec 18 '18 04:12

user1019042


1 Answers

If I understand correctly, the user should never be able to toggle the checkbox manually. Instead it will be toggle programmatically depending on the input value.

You can very simply prevent the default click behavior, so nothing happens when the checkbox is clicked:

<mat-checkbox [checked]="infoBox.value !== ''"
              [disableRipple]="true"
              (click)="$event.preventDefault()">

  <input #infoBox matInput type="text">

</mat-checkbox>
like image 175
Mel Avatar answered Nov 09 '22 00:11

Mel