Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkbox: Disabled checkboxes appear writable until they receive focus #14819

Closed
LoaderB0T opened this issue Feb 15, 2024 · 2 comments · Fixed by #14824
Closed

Checkbox: Disabled checkboxes appear writable until they receive focus #14819

LoaderB0T opened this issue Feb 15, 2024 · 2 comments · Fixed by #14824
Assignees
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@LoaderB0T
Copy link
Contributor

LoaderB0T commented Feb 15, 2024

Describe the bug

When using a p-checkbox with reactive forms, the disabled state of the formControl is not represented by the ui (hover effects, pointer cursor, etc) until the checkbox is clicked or you switch the focus to it by pressing the tab key. Only then the checkbox gets the correct css classes to show the disabled state.

Example gif of this behavior:

My template code for the checkbox:

    <p-checkbox
      [tabindex]="0"
      [formControl]="formControl"
      [binary]="true"
      inputId="my-id"
    ></p-checkbox>

Can be reproduced easily in the stackblitz I sent. Was working in 17.3.3

Environment

Reproducer

https://stackblitz.com/edit/github-p6bxec

Angular version

17.1.2

PrimeNG version

17.7.0

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

20.9.0

Browser(s)

Chrome 121

Steps to reproduce the behavior

No response

Expected behavior

No response

@LoaderB0T LoaderB0T added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Feb 15, 2024
@mehmetcetin01140 mehmetcetin01140 self-assigned this Feb 16, 2024
@mehmetcetin01140 mehmetcetin01140 added Type: Bug Issue contains a bug related to a specific component. Something about the component is not working and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Feb 16, 2024
@mehmetcetin01140 mehmetcetin01140 added this to the 17.8.0 milestone Feb 16, 2024
cetincakiroglu added a commit that referenced this issue Feb 22, 2024
Fixed #14819 - Checkbox | Disabled checkboxes appear writable until t…
@vaibhav65577
Copy link

Hello @LoaderB0T @mehmetcetin01140 @vincent
Is this issue fixed?
I install latest version 17.13.0 and still face same issue.

<p-checkbox
    *ngIf="menu.allowAdd"
    [ngClass]="menu.isAddDisabled ? 'disabled' : ''"
    [disabled]="menu.isAddDisabled"
    [binary]="true"
    formControlName="add"
    [attr.disabled]="menu.isAddDisabled"
  ></p-checkbox>

with this same code, I was able to disable this checkbox in version 17.7.0 but not able to disable the same checkbox in 17.13.0 or in any version after 17.7

@LoaderB0T
Copy link
Contributor Author

@vaibhav65577 What you describe seems to be a different issue. My issue was that the disabled state from the formControl was not correctly detected by the control, your issue sounds like the "disables" input binding of the checkbox does not get detected when using form Controls. AFAIK using [disabled] together with a formControl is deprecated by angular.

My issue has indeed been fixed by the referenced PR.

You could try to handle the disabled state in the formControl itself instead of the binding in the template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants