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>
1

4 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>
2

This way it also becomes not focusable and you won't be able to check it using the keyboard.

    <mat-checkbox
        [checked]="state"
        [class.mat-checkbox-disabled]="false"
        disabled>
    </mat-checkbox>

use the disabled attribute

 <mat-checkbox [ngModel]="checkboxvalue" [disabled]="true"/>

or

<mat-checkbox [ngModel]="checkboxvalue" disabled/>

Refer Example

<mat-checkbox [checked]="checked"
              (click)="change()">

JS file:

change(){
checked=true;
}
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest